アーカイブしようとしているもの: カスタム ビューを含むダイアログが必要ですが、標準のアイコン、タイトル、ボタンがAlertDialog
.
私がやっているのは、このカスタムダイアログクラスです:
public class CustomDialog extends AlertDialog.Builder {
private Activity activity;
private View root;
public CustomDialog(Activity context) {
super(context);
this.activity = context;
}
public void setView(int layoutResID) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
root = inflater.inflate(layoutResID, (ViewGroup) activity.findViewById(R.id.dialog_root), false);
ScrollView scroller = new ScrollView(activity);
scroller.addView(root);
setView(scroller);
}
public void setCustomView(View v) {
ScrollView scroller = new ScrollView(activity);
scroller.addView(v);
setView(scroller);
}
public View getRoot() {
return root;
}
@Override
public AlertDialog create() {
AlertDialog dialog = super.create();
dialog.getWindow().getAttributes().width = LayoutParams.MATCH_PARENT;
return dialog;
}
}
これはかなりうまく機能しTextView
ますが、Honeycomb 以前のデバイスと Honeycomb デバイスでは色が正しくないことが予想されます。私はHolo.Light
テーマを使用しているので、標準のテキストの色は黒ですが、Honeycomb 以前のデバイスのダイアログの背景色も同様です。また、ハニカム デバイスでは、ダイアログの背景は白です。だから私がしたことは、フォルダー内とフォルダー内にa を追加したことdialogTextColor=white
です。次に、スタイル属性をすべてに追加する必要がありましたstyles.xml
values
dialogTextColor=black
values-v11
TextView
カスタムダイアログで使用しています。これは ICS までは機能していましたが、その理由は明らかです -> v11. 変更することもできますが、すべてを正しく行うカスタム ダイアログが必要です。アプリケーションのテーマ、ダイアログの幅、の標準ボタン、タイトル、アイコンAlertDialog
。