我喜欢制作自定义标题栏。最重要的是,我想添加一个带加号的按钮。
制作自定义标题var I follow this link的第一步。但是我在MainActivity.java中遇到了问题。当我到达setContentView(R.layout.activity_main);
行时,我的程序被粉碎了。我的代码如下所示
public class MainActivity extends ListActivity {
String[] presidents = { "Dwight D. Eisenhower", "John F. Kennedy",
"Lyndon B. Johnson", "Richard Nixon", "Gerald Ford",
"Jimmy Carter", "Ronald Reagan", "George H. W. Bush",
"Bill Clinton", "George W. Bush", "Barack Obama"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);
/*
// ---List View--- setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, presidents));
*/
// ---Part 2---
ListView lstView = getListView();
// lstView.setChoiceMode(ListView.CHOICE_MODE_NONE);
// lstView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lstView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_checked, presidents));
}