【发布时间】:2017-04-13 00:22:39
【问题描述】:
我在设置活动中使用自定义布局创建了自定义对话框首选项。这里的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingEnd="?android:attr/scrollbarSize"
android:background="?android:attr/selectableItemBackground"
>
<ImageView
android:id="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dip"
android:layout_marginEnd="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1"
>
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
/>
<TextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="4"
/>
</RelativeLayout>
<!-- ... -->
</LinearLayout>
所有内容都会显示,但标题和摘要没有显示任何值,即使它们有 @android:id。这似乎适用于某些人,但不适用于我。
我从这里获取了我的代码:layout、class 和 xml preference。如果您仔细观察,没有任何操作将标题和摘要视图链接到 xml 首选项文件值,但它们确实如此。如何? 这里我说的是android:title 和android:summary 值。
我不会添加我的自定义偏好代码,但问题不应该存在。我有 4 个构造函数,并且我正确使用了setLayoutResource。
【问题讨论】:
标签: android android-preferences