本文介绍了如何从自定义对话框中删除标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为了实现布局是我的自定义对话框的布局是这样的:
I implemented a layout in order to be my custom dialog layout like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/gray_back"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/mainLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_centerInParent="true">
<ImageView
android:src="@drawable/user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:layout_gravity="center"
android:contentDescription="@string/app_name" />
<EditText
android:id="@+id/username"
android:background="@android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:gravity="center"
android:layout_gravity="center"
android:hint="@string/new_profile_name" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="?android:attr/dividerHorizontal" />
</LinearLayout>
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_below="@id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="0dip"
android:measureWithLargestChild="true">
<Button
android:id="@+id/cancel"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel"/>
<Button
android:id="@+id/ok"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ok"/>
</LinearLayout>
和我创造了它编程是这样的:
And I created it programmatically like this:
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_add_profile);
Button dialogButton = (Button) dialog.findViewById(R.id.cancel);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
但后来我的对话框显示如下:
But then my dialog is showing like this:
我怎么能删除图像的剩余空间布局的顶部?
How can I delete the remaining space from the image to the top of the layout?
我想试试这个:
dialog.setWindowFeature(Window.WINDOW_NO_TITLE);
但它崩溃...我如何删除剩余空间?
but it crashes... How can I remove that remaining space?
推荐答案
创建一个新的样式,添加:
Create a new style, add:
<style name="NoTitleDialog" parent="@android:Theme.Dialog">
<item name="android:windowNoTitle">true</item> </style>
最后:
Dialog d = new Dialog(this, R.style.nameOfStyle);
编辑:
这篇关于如何从自定义对话框中删除标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!