Android 自定义对话框显示 Android 标题栏
我制作了一个像这样的 xml 文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_gravity="bottom"
android:background="#04600F"
android:padding="10dp">
<TextView android:id="@+id/txtMessage"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_height="wrap_content"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/btnOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:textColor="#ffffff"
android:layout_alignParentLeft="true"
android:background="@drawable/black_menu_button"
android:layout_marginLeft="5dip"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<Button android:id="@+id/btnTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:background="@drawable/blue_menu_button"
android:layout_marginRight="5dip"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</LinearLayout>
我尝试像这样访问它:
final Dialog dialog = new Dialog(ctx,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog.setContentView(R.layout.myxml);
.....
它在屏幕上看起来完全是我想要的,在它的底部。我的应用程序在 AndroidManifest 上进行了以下设置:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
我所做的唯一缺点是,只要我的对话框可见,Android 标题栏(带有电池/信号...的标题栏)就会可见。我怎样才能禁用它?
稍后编辑
谢谢您向我指出,解决方案确实相当简单
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
I have made an xml file like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_gravity="bottom"
android:background="#04600F"
android:padding="10dp">
<TextView android:id="@+id/txtMessage"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_height="wrap_content"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/btnOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:textColor="#ffffff"
android:layout_alignParentLeft="true"
android:background="@drawable/black_menu_button"
android:layout_marginLeft="5dip"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<Button android:id="@+id/btnTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:background="@drawable/blue_menu_button"
android:layout_marginRight="5dip"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</LinearLayout>
And I try to access it like this:
final Dialog dialog = new Dialog(ctx,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog.setContentView(R.layout.myxml);
.....
It looks on the screen exactly how I want it, on the bottom of it. My application has the following set on AndroidManifest:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
The only draw back of what I did is the fact that the Android title bar (the one with battery/signal... ) becomes visible as long as my Dialog is visible. How can I disable it ?
Later edit
Thank you for pointing that to me, the solution was fairly simple indeed
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案非常简单,尝试下面的代码:
The solution was very simple, try the code below: