Question

I want to use the same method in 3 activities( to use the same custom action bar for the three ). so I created a class " Actionbar_methods" that contain the methods I want to use :

public class Actionbar_methods extends ActionBarActivity{




public  void setupActionBar() {  // action bar 


      final LayoutInflater inflater = (LayoutInflater) this
          .getSupportActionBar().getThemedContext()
          .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      final View customActionBarView = inflater.inflate(
          R.layout.second_actionbar, null);




    final ActionBar actionBar = this.getSupportActionBar();
      actionBar.setDisplayOptions(
          ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM | 
          ActionBar.DISPLAY_SHOW_HOME | 
          ActionBar.DISPLAY_SHOW_TITLE);

      actionBar.setCustomView(customActionBarView, 
            new ActionBar.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, 
                ViewGroup.LayoutParams.MATCH_PARENT
            )
           );
   }



protected void setActiobarTitle(String title)
 {

    View v = getSupportActionBar().getCustomView();
    TextView titleTxtView = (TextView) v.findViewById(R.id.title);
    titleTxtView.setText(title);
 }



 }

I have no errors so far! but I have no idea of how can I call theses methods in my activities. so any help or documentation will be appreciated

Was it helpful?

Solution

To use these methods in other activities, extend the Actionbar_methods class.
Something like :

public class FirstActivity extends Actionbar_methods {
//Add other methods here. 
//You'll be able to use setupActionBar() method here. 

@Override
    protected void onCreate(Bundle savedInstanceState) {

        setContentView(R.layout.first_activity);
        super.onCreate(savedInstanceState);

        setupActionBar();

    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top