Android 如何使用首选项活动访问布局中设置的小部件
我正在创建首选项活动,因为我正在使用布局添加自定义首选项屏幕,并且我希望动态更新值 代码如下:Android 如何使用首选项活动访问布局中设置的小部件,android,preferenceactivity,Android,Preferenceactivity,我正在创建首选项活动,因为我正在使用布局添加自定义首选项屏幕,并且我希望动态更新值 代码如下: <PreferenceCategory android:key="more_category" android:title="More Wallpapers " > <Preference android:key="more_apps" android:layout="@layout/more_apps" /> 这
<PreferenceCategory
android:key="more_category"
android:title="More Wallpapers " >
<Preference
android:key="more_apps"
android:layout="@layout/more_apps" />
这是我的布局more_apps.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="5dp"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/image_one"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/description_text"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:layout_below="@+id/title_text"
android:layout_toRightOf="@+id/image_one"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/image_one"
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@drawable/launcher" />
我想在运行时更新我的文本视图和图像,如何在首选项活动中访问
请帮助您需要在xml布局中使用“提及您的首选项”类,如下面的代码所示
<PreferenceCategory
android:key="more_category"
android:title="More Wallpapers " >
<com.myapp.myclass android:key="more_apps"/>
</PreferenceCategory>
通过这种方式,您可以创建自定义首选项活动并执行任何操作。您需要在xml布局中使用“提及您的首选项”类,如下面的代码所示
<PreferenceCategory
android:key="more_category"
android:title="More Wallpapers " >
<com.myapp.myclass android:key="more_apps"/>
</PreferenceCategory>
通过这种方式,您可以创建自定义首选项活动并执行任何操作。这对我不起作用;充气机刚刚返回空。这对我不起作用;充气机刚刚返回空值。