Android: Adding static header to the top of a ListActivity

前端 未结 5 826
别那么骄傲
别那么骄傲 2020-11-28 23:07

Currently I have a class that is extending the ListActivity class. I need to be able to add a few static buttons above the list that are always visible. I\'ve attempted to

5条回答
  •  囚心锁ツ
    2020-11-28 23:32

    The ListView answer above is useful but scrolls with the list and doesn't keep the header graphics at the top. The best solution I've found is to set a custom title to the activity. Here is what my constructor looks like:

    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.your_listview_layout);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.your_header);
        ...
    

    Where your_listview_layout.xml configures a ListView, and your_header.xml contains whatever custom header layout that you like. Just note that the three lines above must be called in exactly that order to not cause run-time problems.

    The tutorial that helped me was http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/ and you can find many related pages on Stack Overflow by searching for the term "setFeatureInt"

提交回复
热议问题