我在设置活动中使用自定义布局制作了自定义对话框首选项。这里的布局:为自定义首选项自动设置标题和摘要
<?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:title'和'android:summary'值没有被应用到我的布局中的textviews。 –