==20.Settings 内置选项在一级菜单 activity 方式==
① 在 AndroidManifest.xml 添加如下代码
<activity android:name=".HardKey"
android:label="Mrlove"
android:icon="@drawable/ic_home_wikofeatures"
android:taskAffinity="">
<intent-filter android:priority="1">
<action android:name="com.android.settings.HARDKEY" />
<action android:name="android.settings.HARDKEY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<!--在category中的物理位置(按优先级排序时用到,并不是指第9个位置,数越大优先级越大越靠前)-->
<intent-filter android:priority="9">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<!--此项在主setting位置(ia.homepage)-->
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.homepage" />
<meta-data android:name="com.android.settings.ACTIVITY_ACTION"
android:value="com.android.settings.HardKey" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
② 实现 HardKey 这个 activity 代码如下
package com.android.settings;
import android.app.Activity;
import android.os.Bundle;
public class HardKey extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hardkey);
}
}
③ 创建 hardkey.xml 代码如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="hello world" />
</LinearLayout>