简体   繁体   中英

Android - strange layout display in custom DialogPreference

I have a custom DialogPreference with my own layout defined. The layout file is as follows:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"

android:paddingTop="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/enter_password_label"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword">

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/confirm_password_label"
    android:textAppearance="?android:attr/textAppearanceMedium" 
    />

<EditText
    android:id="@+id/editText2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword" 
    />

On the displayed dialog both TextViews are missing:

在此处输入图片说明

What is the reason of TextViews not being displayed?

One of the reason for this behavior is due to manufacturer's customization of themes. Other reasons could be that the selected text appearance has same color as of background. To avoid this, you may simply set a color to your TextView, for eg:

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/enter_password_label"
    android:textAppearance="?android:attr/textAppearanceLarge"

    android:textColor="#000000" />

* Also make sure android:text does have a text to show on screen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM