自定义对话框没有标题和边框自定义、边框、对话框、标题

由网友(冇愛蕪緣)分享简介:基于在code这里,http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog 。我成功地能够创建带有背景和内部按键的自定义对话框,但还是有一些不正确的。仍然为标题栏的空间,并且周围有观点边框。如何摆脱这些标题和边框?这是我的对话框对话...基于在code这里

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

这是我的对话框

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

和这里是我的暂停布局

 < XML版本=1.0编码=UTF-8&GT?;
< 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>
    < TableLayout机器人:layout_width =WRAP_CONTENT机器人:ID =@ + ID / tableLayout1机器人:layout_height =WRAP_CONTENT>
        < ImageButton的机器人:SRC =@可绘制/ pause_button_quit机器人:layout_width =WRAP_CONTENT机器人:背景=@可绘制/ pause_button_quit机器人:ID =@ + ID / imageButton2机器人:layout_height =WRAP_CONTENT> < / ImageButton的>
        < ImageButton的机器人:SRC =@可绘制/ pause_button_option机器人:layout_width =WRAP_CONTENT机器人:背景=@可绘制/ pause_button_option机器人:ID =@ + ID / imageButton1机器人:layout_height =WRAP_CONTENT> < / ImageButton的>
    < / TableLayout>
< / LinearLayout中>
 

解决方案 html如何给标题设置边框和底纹,给标题加边框怎么设置

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

  

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

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.

阅读全文

相关推荐

最新文章