我有一个对话框,但有些背景图像是未知的。我该如何删除该图像。请指导我。
答案 0 :(得分:2)
您必须扩展Dialog Class,为您的对话框构建类似
的xml文件<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Do you Want to bookmark?"
android:gravity="center"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No" />
<Button
android:id="@+id/button_yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yes" />
</LinearLayout>
</LinearLayout>
当然你可以做一些自定义
对于您可以这样做的自定义对话框类
public class CustomizeDialog extends Dialog implements OnClickListener {
Button okButton;
public CustomizeDialog(Context context) {
super(context);
/** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
yesButton = (Button) findViewById(R.id.button_yes);
yesButton.setOnClickListener(this);
noButton = (Button) findViewById(R.id.button_no);
noButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button_yes:
dismiss();
//doSomething
break;
case R.id.button_no:
dismiss();
//doSomethingElse
break;
}
}
希望这会对你有所帮助 你必须发布你的代码,找出为什么这些背景框出现给你,但我提到的行为应该为你解决问题
答案 1 :(得分:1)
可能会发生这种情况,因为您使用标准AlertDialog
并设置了内容视图+没有标题(尽管您没有设置标题,但它的空间将保留在对话框中)。
扩展Dialog
类,然后按照您的意愿构建对话框。此外,如果您想使用自己的Dialog
背景,请实现扩展Theme.Dialog
并覆盖的主题:
<item name="android:windowBackground">@android:drawable/panel_background</item>
用你自己的drawable。