How to persist a View across Activities in Android

前端 未结 5 1404
遇见更好的自我
遇见更好的自我 2021-02-03 15:43

I\'m working on an Android application and I\'d like to maintain a top-bar of sorts in most of my Activities, as per the Twitter and Facebook applications. How is this done? I\'

5条回答
  •  太阳男子
    2021-02-03 16:14

    Break the title bar out into a separate layout, and use the include xml tag. I do that in a few of my apps. Each of your activities can inherit from a Base Activity that contains events for the included layout, e.g. if the title bar has buttons.

    Example pseudocode below.

    title.xml

    
    

    activity layouts for each layout

    
        
    
    

    BaseActivity

    public class BaseActivity extends Activity {
         public void buttonClick(View v) {
              // do something interesting.
         }
    }
    
    public class OtherActivity extends BaseActivity {}
    

提交回复
热议问题