Android自定义设计对话框无标题栏 [英] Android custom design Dialog prob without title bar

查看:143
本文介绍了Android自定义设计对话框无标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下xml来设计自定义对话框。

I using following xml to design a custom Dialog.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@drawable/wound_screener_bg"
    android:layout_height="match_parent" >

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:paddingTop="15dp"
        android:paddingRight="70dp"
        android:textColor="#5A5C5E"
        android:paddingLeft="70dp"
        android:id="@+id/bodyPartText"
        android:layout_centerHorizontal="true"
        android:text="You selected the arm"/>
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="normal"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:textColor="#727576"
        android:id="@+id/confirmText"
        android:layout_below="@id/bodyPartText"
        android:layout_centerHorizontal="true"
        android:text="Is that correct?"/>
    <View 
        android:layout_width="15dp"
        android:layout_height="1dp"
        android:layout_below="@id/confirmText"
        android:layout_centerHorizontal="true"
        android:id="@+id/buffer"></View>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="YES"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:paddingRight="30dp"
        android:paddingLeft="30dp"
        android:background="#DDDDDD"
        android:textColor="#EB9093"
        android:id="@+id/yesBtn"
        android:layout_below="@id/confirmText"
        android:layout_toLeftOf="@id/buffer"/>  
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="NO"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:paddingRight="30dp"
        android:paddingLeft="30dp"
        android:id="@+id/noBtn"
        android:background="#DDDDDD"
        android:textColor="#EB9093"
        android:layout_below="@id/confirmText"
        android:layout_toRightOf="@id/buffer"/>
</RelativeLayout>

现在我使用以下代码显示对话框。

Now I using following code to display the dialog box.

Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.bodypart_comfirm);


TextView bodyPartText = (TextView) dialog.findViewById(R.id.bodyPartText);
Button yesBtn = (Button) dialog.findViewById(R.id.yesBtn);
Button noBtn = (Button) dialog.findViewById(R.id.noBtn);

bodyPartText.setText("You selected the " + partName);

noBtn.setOnClickListener(new OnClickListener() {
 @Override
 public void onClick(View v) {
   dialog.dismiss();
 }
});     

yesBtn.setOnClickListener(new OnClickListener() {
 @Override
 public void onClick(View v) {
   .............
   .............

 }
});

dialog.show();

它提供了一个如下所示的对话框。

It gives a dialog like below.

现在如果我删除dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)的行,它给出了正确的设计,但标题栏,但我不是标题栏。

Now if I remove the line of "dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);", it gives the proper design, but with the title-bar, but I do not the title bar.

什么是我的代码中的问题吗?如何解决?

What is the problem in my code? How to solve it?

推荐答案

将此样式添加到您的styles.xml文件中:

add this style to your styles.xml file :

<style name="FullHeightDialog" parent="android:style/Theme.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>

,然后用以下方式设置对话框:

and then instanciate your dialog with :

LayoutInflater inflater=LayoutInflater.from(mContext);
View contentView=inflater.inflate(R.layout.instructions_popup_layout, null);
final Dialog dialog=new Dialog(this, R.style.FullHeightDialog);
dialog.setContentView(contentView);
Button button=(Button) dialog.findViewById(R.id.okButton);

这篇关于Android自定义设计对话框无标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆