在string.xml裏:
<com.android.deskclock.settings.AlarmVolumePreference android:key="volume_setting" android:layout="@layout/alarm_volume_preference" android:title="@string/alarm_volume_title" />
自定義了Prefernce,加載的默認layout爲alarm_volume_preference.xml
但是因爲需要適應其它平臺[因爲特殊設備的分辨率的原因],需要在AlarmVolumePreference裏根據不同情況加載layout.
查詢/frameworks/base/core/java/android/preference/Preference.java
/** * Sets the layout resource that is inflated as the {@link View} to be shown * for this Preference. In most cases, the default layout is sufficient for * custom Preference objects and only the widget layout needs to be changed. * <p> * This layout should contain a {@link ViewGroup} with ID * {@link android.R.id#widget_frame} to be the parent of the specific widget * for this Preference. It should similarly contain * {@link android.R.id#title} and {@link android.R.id#summary}. * * @param layoutResId The layout resource ID to be inflated and returned as * a {@link View}. * @see #setWidgetLayoutResource(int) */ public void setLayoutResource(@LayoutRes int layoutResId) { if (layoutResId != mLayoutResId) { // Layout changed mRecycleEnabled = false; } mLayoutResId = layoutResId; }
將新增的layout放置到overlay裏,然後在AlarmVolumePreference的構造方法裏調用setLayoutResource:
public AlarmVolumePreference(Context context, AttributeSet attrs) { super(context, attrs); if(滿足xx條件) { setLayoutResource(R.layout.alarm_volume_preference_xx); //不滿足該條件則加載默認layout. } }
相关推荐
导语:PreferenceActivity是一个方便设置管理的界面,但是对于界面显示来说比较...使用Preference的android:@layout属性 1)xml文件中preference的添加 代码如下: <Preference android:layout=”@layout/youmi_ad”
上篇博文代码实现了Android自带的preference组件,本文将通过实例讲解自定义preference组件。 主要通过以下几步来实现: 1.定义需要的layout布局res->layout->xml文件; 2.通过继承Preference类,来实现自定义...
Preference主要实现一些配置数据,一些我们上次点击选择的内容,我们希望在下次应用调起的时候依然有效,无须用户再一次进行配置或选择。Android提供preference这个键值对的方式来处理这种情况,自动保存这些数据,...
android Preference自定义样式
Based on support-preference from Android Support Library, adding a lot of exciting features. Sample How to use add dependencies // replace with version above implementation 'moe.shizuku.preference...
preference测试
Preference组件是android的SharePreferences的衍生品,Preference组件的状态值是默认永久的保存在/data/data/包名/shared_prefs 目录下,因为Android系统的Setting应用及一些符合Android设计思想的应用的设置界面...
libgdx Preference
Laravel开发-preference Laravel的简单偏好包
android-support-v7-preference.jar
Android Preference Framework源码~~~~~~~~~~~~~~~~~
手把手教你设计像系统设置那样的操作界面,和用法
MyEclipse界面风格preference导出文件
Android中preference的使用,使用详解.
ViewPager实现滑动的Preference页面且带ActionBar
sRGB_v4_ICC_preference.icc
我们的app有时常需要包含Settings,那我们该怎样允许app使用Settings呢?这里我们就需要用到Preference类。
安卓Android源码——Preference_Demo.rar
Constrained Preference Embedding for Item Recommendation