[转载]关于自定义标题-Android开发进阶&经验分享-eoe Android开发者社区_Android开发论坛.
一般情况下,自定义标题时,按以下写法即可
|
01
02
03
|
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //声明使用自定义标题setContentView(R.layout.list);getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);//自定义布局赋值 |
但是如果遇到特殊的Activity,如ListActivity,不需要setContentView,此时,如果直接把setContentView去掉,那么自定义的标题就会也不显示了。
如果依然调用setContentView,传入一个空的布局文件,我得到了一个报错信息:

布局中必须要有个id为@Android:id/list的listview的listview
于是在空布局中加入个空listview,id为@Android:id/list的listview
|
01
02
03
04
05
06
07
08
09
10
|
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView> </LinearLayout> |
然后再调用setcontentview(R.layout.empty_list);
|
01
02
03
04
05
06
07
08
09
10
11
|
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //声明使用自定义标题 setContentView(R.layout.list); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);//自定义布局赋值 ArrayList<Map<String,String>> a = new ArrayList<Map<String,String>>(); Map<String,String> b = new HashMap<String,String>(); b.put("aaa", "aaa"); a.add(b); setListAdapter(new SimpleAdapter(this,a, R.layout.title, new String[]{"aaa"}, new int[]{R.id.textView1})); |
这样就ok了

Mikel