在我的android项目中,我在活动xml文件中添加了一个背景图片。我也将样式设置为不在顶部显示标题栏。此活动有一个按钮,按下该按钮将显示一个对话框。
最近我刚刚添加了图片并使其不显示标题栏,然后当我去测试它,然后点击按钮时,对话框的宽度就像是100px。在我添加背景图像之前,我的对话框宽度很好,它填充了父级。
这是用于对话框的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_vertical_margin"
android:orientation="vertical" >
<TextView
android:id="@+id/textview_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+string/email" />
<EditText
android:id="@+id/textinput_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:text="james.jn1981@gmail.com" />
<TextView
android:id="@+id/textview_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+string/password" />
<EditText
android:id="@+id/textinput_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:text="123" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/button_exit"
style="@style/footer"
android:background="@drawable/bg_footer"
android:text="@+string/cancel" />
<Button
android:id="@+id/button_login"
style="@style/footer"
android:background="@drawable/bg_footer"
android:text="@+string/ok" />
</LinearLayout>
</LinearLayout>
有谁知道这里有什么不对吗?
修改
这导致了这个问题:
android:theme="@android:style/Theme.NoTitleBar"
如何删除标题栏并使对话框宽度保持正常宽度?
由于
答案 0 :(得分:0)
试试这个:
//Use android.R.style.Theme or Theme_light
Dialog dialog = new Dialog(context, android.R.style.Theme_Light);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Whatever your layout file is
dialog.setContentView(R.layout.MyCustomDialogLayout);
dialog.show();