Android 获取自定义对话框的全宽 [英] Android get full width for custom Dialog
本文介绍了Android 获取自定义对话框的全宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我创建的自定义对话框没有全高,我无法更改和自定义它.例如,请参阅此屏幕截图:
我的代码:
final Dialog contacts_dialog = new Dialog(ActivityGroup.this, R.style.theme_sms_receive_dialog);contacts_dialog.setContentView(R.layout.dialog_schedule_date_time);contacts_dialog.setCancelable(true);contacts_dialog.setCanceledOnTouchOutside(true);contact_dialog.show();
布局:
<线性布局android:layout_width="fill_parent"android:layout_height="wrap_content"android:background="@drawable/shape_header_dialog_background"机器人:方向=水平"android:padding="4dp" ><文本视图android:id="@+id/TextView21"android:layout_width="fill_parent"android:layout_height="fill_parent"机器人:layout_marginRight="5dp"机器人:layout_weight="2"android:gravity="center_vertical|right"android:text="@string/choose_schedule_time_date"android:textColor="#ffffff"android:textSize="14sp"android:textStyle="粗体"/><图像视图android:id="@+id/ImageView03"android:layout_width="50dp"android:layout_height="50dp"android:layout_marginTop="0dp"android:background="@drawable/icon_scudule_time"/></LinearLayout></LinearLayout>
风格:
Java
Dialog d=new Dialog(mContext,R.style.mydialog);……………………myDialog.show();窗口窗口 = myDialog.getWindow();window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
in my application my created custom dialog dont have full height and i can not change and customize that.for example see this screen shot:
My code:
final Dialog contacts_dialog = new Dialog(ActivityGroup.this, R.style.theme_sms_receive_dialog);
contacts_dialog.setContentView(R.layout.dialog_schedule_date_time);
contacts_dialog.setCancelable(true);
contacts_dialog.setCanceledOnTouchOutside(true);
contacts_dialog.show();
layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutRoot"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@null"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_header_dialog_background"
android:orientation="horizontal"
android:padding="4dp" >
<TextView
android:id="@+id/TextView21"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="5dp"
android:layout_weight="2"
android:gravity="center_vertical|right"
android:text="@string/choose_schedule_time_date"
android:textColor="#ffffff"
android:textSize="14sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/ImageView03"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="0dp"
android:background="@drawable/icon_scudule_time" />
</LinearLayout>
</LinearLayout>
Style:
<style name="theme_sms_receive_dialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="numberPickerStyle">@style/NPWidget.Holo.Light.NumberPicker</item>
</style>
解决方案
You need to get the current Window and set it's LayoutParams
like so:
Dialog d=new Dialog(mContext);
.........
.........
myDialog.show();
Window window = myDialog.getWindow();
window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
Alternative(if above solution does't works)
In case above code not works well you can use a workaround
styles.xml
<style name="mydialog"></style>
Java
Dialog d=new Dialog(mContext,R.style.mydialog);
.........
.........
myDialog.show();
Window window = myDialog.getWindow();
window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
这篇关于Android 获取自定义对话框的全宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文