在Android AlertDialog.Builder风格 [英] AlertDialog.Builder style on Android
本文介绍了在Android AlertDialog.Builder风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想修改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.
这篇关于在Android AlertDialog.Builder风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文