我有一个偏好 android:layout gft。
我已经在xml文件中的偏好设置的android:layout属性中设置了布局。
现在我需要初始化布局中的一个按钮(它是一个+1按钮)。
我需要在onCreate方法中获取该按钮(它是一个+1按钮),但当我使用findViewById(button_id)
时,它返回null。
是否有一些方法可以获取此偏好的视图?
更新:似乎在添加偏好xml后偏好设置没有被创建,所以我得到了null。在哪里可以调用findViewById,使按钮已经被创建?
谢谢。
偏好设置xml:
<Preference android:title="Rate this app"
android:key="rate"
android:widgetLayout="@layout/plusone_pref"/>
</PreferenceScreen>
偏好设置布局的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.plus.PlusOneButton xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="@+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:focusable="false"
plus:size="standard" />