1.
SettingsActivity extends
PreferenceActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
final boolean isCustom
=requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_setting);
addPreferencesFromResource(R.xml.pref_camera);
addPreferencesFromResource(R.xml.pref_flying);
addPreferencesFromResource(R.xml.pref_general);
addPreferencesFromResource(R.xml.pref_other);
log.d(TAG +
" onCreate isCustom = "+isCustom);
if(isCustom){
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.activity_setting_title);
}
}
注:requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)一定要放在
super.onCreate(savedInstanceState)之前。
2.
AndroidManifest.xml
android:name="settings.SettingsActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/title_activity_settings"
android:theme="@style/Default"
>
3.
Values/style.xml Default Style的定义
20dip
#FFffffff
0dp
@color/dark
@android:color/black
@color/window_bg
@null
50.0dip
@style/CustomWindowTitleText
@style/CustomWindowTitleBackground
false
4.
Value/color.xml
#000000
#c7c7c7
name="transparent">#00000000
5.
Layout/layout_setting.xml
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/window_bg"
android:orientation="vertical"
android:padding="10dp" >
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="@color/transparent"
android:scrollbarStyle="outsideOverlay"
android:fadingEdgeLength="0dp"
android:scrollbars="none"
android:fadingEdge="none"
android:listSelector="#00000000" />
6.
layout/ activity_setting_title.xml
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/top_bar">
android:id="@+id/returnBtn_Settings"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="-5dp"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:onClick="onReturn"
android:scaleType="centerInside"
android:src="@drawable/selector_back_btn"
/>
android:id="@+id/setting_title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="@android:color/white"
android:text="@string/title_activity_settings"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
7.xml/pref_camera.xml
>
android:layout="@layout/pref_category"
android:title="@string/pref_camera_title">
android:layout="@layout/pref_list_item_top"
android:title="@string/pref_camera_autohide_title"
android:defaultValue="false"
android:key="toolbar_auto_hide"
/>
android:layout="@layout/pref_list_item_mid"
android:key="camera_whenbreak"
android:title="@string/pref_camera_whenbreak_title"
android:widgetLayout="@layout/pref_widget_more">
android:layout="@layout/pref_list_item_bot"
android:defaultValue="2"
android:key="resolution"
android:entries="@array/pref_camera_preview_resolution_titles"
android:entryValues="@array/pref_camera_preview_resolution_values"
android:negativeButtonText="@string/settings_cancel"
android:positiveButtonText="@null"
android:title="@string/pref_camera_preview_title"
android:widgetLayout="@layout/pref_widget_more"/>
由于XML文件以及图片资源太多,我就不一一罗列了,需要请发邮件!
Email:zhaoch86@sina.cn
效果图: