我想修改AlertDialog.Builder的标题和正文的风格。结果儿子我用setCustomTitle和的setView到达这一点。结果下面是简化code:
I want to modify AlertDialog.Builder's title and body style. Son I use setCustomTitle and setView to arrive this. Below is the simplify code:
private AlertDialog dialog;
public void Showdialog() {
LayoutInflater inflaterTitle = getLayoutInflater();
View TitleView = inflaterTitle.inflate(layout, (ViewGroup)findViewById(id));
TextView Title = (TextView)TitleView.findViewById(id);
Title.setText("Title");
LayoutInflater inflaterBody = getLayoutInflater();
View BodyView = inflaterBody.inflate(layout, (ViewGroup)findViewById(id));
TextView Body = (TextView)BodyView.findViewById(id);
Body.setText("Body");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCustomTitle(TitleView);
builder.setView(BodyView);
dialog = builder.create();
dialog.show();
}
于titleview和BodyView与BULE背景。结果该节目对话框如下图所示。结果结果包含有2个黑色。结果我怎样才能删除它?
The TitleView and BodyView with bule background. The show dialog as below. There contain 2 black. How can I remove it?
相反的,如果你想为对话框的自定义布局,然后使用下面code。
Instead of that, if you want to have custom layout for dialog then use below code.
final Dialog dialog = new Dialog(SplashActivity.this,R.style.CustomDialogTheme);
dialog.getWindow();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.internet_dialog);
dialog.setCancelable(false);
Button retryBtn = (Button) dialog.findViewById(R.id.retryBtn);
Button cancel = (Button) dialog.findViewById(R.id.cancelBtn);
retryBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
checkForInternetAndNextFlow();
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
finish();
}
});
dialog.show();
styles.xml中值resouces:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:fitsSystemWindows">true</item>
<!-- <item name="android:colorBackgroundCacheHint">#00000000</item>
<item name="android:background">#00000000</item> -->
</style>
这将帮助你很多。您可以设置任何视图,按您的需求。
This will help you a lot. You can set any view as per your need.