如何在android的AlertDialog中包含自定义标题视图?
如何在alertDialog中包含自定义标题栏?我知道android sdk提供了setCustomTitle方法,但它不起作用 编辑: 但上述代码不起作用 注: 我不寻找自定义对话框,但只想使其标题布局自定义..如下所示如何在android的AlertDialog中包含自定义标题视图?,android,android-alertdialog,custom-titlebar,Android,Android Alertdialog,Custom Titlebar,如何在alertDialog中包含自定义标题栏?我知道android sdk提供了setCustomTitle方法,但它不起作用 编辑: 但上述代码不起作用 注: 我不寻找自定义对话框,但只想使其标题布局自定义..如下所示 DisplayDialog d = new DisplayDialog(this); d.show(); public class DisplayDialog extends Dialog implements android.view.View.O
DisplayDialog d = new DisplayDialog(this);
d.show();
public class DisplayDialog extends Dialog implements android.view.View.OnClickListener
{
public DisplayDialog(Context c)
{
super(c, R.style.Theme_Dialog_Translucent);
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setCanceledOnTouchOutside(false);
setContentView(R.layout.your_layout);
}
}
将此代码段添加到您的strings.xml
<style name="Theme_Dialog_Translucent" parent="android:Theme.Dialog">
<item name = "android:windowBackground">@color/transparent</item>
</style>
<color name="transparent">#00000000</color>
@彩色/透明
#00000000
使用
disclose()
要关闭对话框您不应在第一行使用.show方法,请使用以下代码:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.titlebar, null);
alert.setCustomTitle(view);
alert.setMessage("helo");
alert.show();
这将显示如何创建自定义对话框我知道如何创建自定义对话框,但我不想要任何自定义对话框,但只需要自定义标题,这样我就可以将按钮添加到其标题中,无论如何,感谢没有工作方式?是不是有什么错误?或者干脆不显示自定义标题?我认为代码是正确的,应该可以工作。@Vikram显示默认标题栏。
AlertDialog.Builder alert = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.titlebar, null);
alert.setCustomTitle(view);
alert.setMessage("helo");
alert.show();