簡體   English   中英

當我為活動設置背景圖像時,Android對話框的寬度會變得很小嗎?

[英]Android dialog box width gets really small when I set a background image for an activity?

在我的android項目中,我向活動xml文件添加了背景圖片。 同樣,我將樣式設置為不在頂部顯示標題欄。 該活動具有一個按鈕,當按下該按鈕時將顯示一個對話框。

最近,我只是添加了圖像,使它不顯示標題欄,然后當我進行測試時,然后單擊按鈕,對話框的寬度就像100px。 在添加背景圖像之前,我對話框的寬度很好,它可以填充父級。

這是用於對話框的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/activity_vertical_margin"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textview_email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@+string/email" />

        <EditText
            android:id="@+id/textinput_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textEmailAddress"
            android:text="james.jn1981@gmail.com" />

        <TextView
            android:id="@+id/textview_password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@+string/password" />

        <EditText
            android:id="@+id/textinput_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPassword"
            android:text="123" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button_exit"
            style="@style/footer"
            android:background="@drawable/bg_footer"
            android:text="@+string/cancel" />

        <Button
            android:id="@+id/button_login"
            style="@style/footer"
            android:background="@drawable/bg_footer"
            android:text="@+string/ok" />

    </LinearLayout>

</LinearLayout>

有人知道這是怎么回事嗎?

編輯:

這是導致問題的原因:

        android:theme="@android:style/Theme.NoTitleBar"

如何刪除標題欄並仍然使對話框的寬度為正常寬度?

謝謝

嘗試這個:

    //Use android.R.style.Theme or Theme_light
    Dialog dialog = new Dialog(context, android.R.style.Theme_Light);            
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    //Whatever your layout file is
    dialog.setContentView(R.layout.MyCustomDialogLayout);    
    dialog.show();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM