自定义对话框没有标题和边框 [英] Custom Dialog without title and border

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

问题描述

基于在code这里

, <一href="http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog">http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog 。我成功地能够创建带有背景和内部按键的自定义对话框,但还是有一些不正确的。仍然为标题栏的空间,并且周围有观点边框。如何摆脱这些标题和边框?

这是我的对话框

 对话pauseMenu =新的对话框(这一点,R.xml.pause_dialog);
pauseMenu.setContentView(R.layout.pause_menu);
返回pauseMenu;
 

和这里是我的暂停布局

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT; LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / linearLayout1机器人:layout_width =WRAP_CONTENT机器人:后台=@可绘制/ pause_menu_cropped机器人:layout_gravity =中心安卓重力=中心| center_horizo​​ntal&GT;
    &LT; TableLayout机器人:layout_width =WRAP_CONTENT机器人:ID =@ + ID / tableLayout1机器人:layout_height =WRAP_CONTENT&GT;
        &LT; ImageButton的机器人:SRC =@可绘制/ pause_button_quit机器人:layout_width =WRAP_CONTENT机器人:背景=@可绘制/ pause_button_quit机器人:ID =@ + ID / imageButton2机器人:layout_height =WRAP_CONTENT&GT; &LT; / ImageButton的&GT;
        &LT; ImageButton的机器人:SRC =@可绘制/ pause_button_option机器人:layout_width =WRAP_CONTENT机器人:背景=@可绘制/ pause_button_option机器人:ID =@ + ID / imageButton1机器人:layout_height =WRAP_CONTENT&GT; &LT; / ImageButton的&GT;
    &LT; / TableLayout&GT;
&LT; / LinearLayout中&GT;
 

解决方案

一个对话框不能没有标题创建。该教程再往下它提到:

  

与基地对话框中所做的对话框   类必须有一个标题。如果不这样做   调用的setTitle(),则使用的空间   为标题是空的,但仍   可见。如果你不想要一个标题   所有的,那么你应该创建   使用AlertDialog自定义对话框   类。但是,因为一个AlertDialog   创建最简单的   AlertDialog.Builder类,你不   有权访问的setContentView(int)的   上述方法中使用。相反,必须   使用的setView(查看)。此方法接受   View对象,所以你需要夸大   从布局的根查看对象   XML。

<一个href="http://stackoverflow.com/questions/3728990/how-to-create-a-completely-custom-dialogue-popup-in-android-change-overlay-colou/3736057#3736057">This回答解决这两个称号,并使用自定义样式的边界问题。

Based on the code here, http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog . I am successfully able to create a custom dialog with background and buttons inside, but there's still something not right. there still a space for title bar, and there are border around the view. how to get rid of these title and border?

here is my dialog

Dialog pauseMenu = new Dialog(this,R.xml.pause_dialog);
pauseMenu.setContentView(R.layout.pause_menu);
return pauseMenu;

and here is my pause layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:background="@drawable/pause_menu_cropped" android:layout_gravity="center" android:gravity="center|center_horizontal">
    <TableLayout android:layout_width="wrap_content" android:id="@+id/tableLayout1" android:layout_height="wrap_content">
        <ImageButton android:src="@drawable/pause_button_quit" android:layout_width="wrap_content" android:background="@drawable/pause_button_quit" android:id="@+id/imageButton2" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:src="@drawable/pause_button_option" android:layout_width="wrap_content" android:background="@drawable/pause_button_option" android:id="@+id/imageButton1" android:layout_height="wrap_content"></ImageButton>
    </TableLayout>
</LinearLayout>

解决方案

A Dialog cannot be created without a title. Further down in that tutorial it mentions:

A dialog made with the base Dialog class must have a title. If you don't call setTitle(), then the space used for the title remains empty, but still visible. If you don't want a title at all, then you should create your custom dialog using the AlertDialog class. However, because an AlertDialog is created easiest with the AlertDialog.Builder class, you do not have access to the setContentView(int) method used above. Instead, you must use setView(View). This method accepts a View object, so you need to inflate the layout's root View object from XML.

This answer solves both the title and the border problem using a custom style.

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

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