将自定义布局添加到PreferenceFragment [英] Adding custom layout to PreferenceFragment

查看:102
本文介绍了将自定义布局添加到PreferenceFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有首选项屏幕层次结构的首选项片段.我想添加一个自定义布局来定义关于作者"部分,将imageview添加到元素和链接(意向浏览器).我进行了搜索,但没有找到有关此主题的任何资源.

I have a preference fragment with a preference screen hierarchy. I would like to add a custom layout to define an "about the author" section, adding imageview to an element and a link (intent to browser). I searched but I didn't find any resources about this topic.

推荐答案

在您的首选项xml文件( res/xml/prefs.xml )中,添加带有 Preference 的自定义布局:

In your preference xml file (res/xml/prefs.xml), add a Preference with a custom layout:

<Preference
    android:layout="@layout/custom_preference"/>

带有 ImageView TextView 且带有链接的 layout/custom_preference.xml 的示例,该链接将在浏览器中打开:

Example of layout/custom_preference.xml with an ImageView and a TextView with a link that will be opened in the browser:

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_book" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="http://www.mylink.com"
        android:autoLink="all"/>
</LinearLayout>

这是屏幕截图中的最后一个首选项:

It's the last preference in the screenshot:

这篇关于将自定义布局添加到PreferenceFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆