0

I followed an online tutorial teaching how to build a custom title bar in android. After you build the layout, here is how to add it onto an activity:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
... 
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

And if you add onClickListeners on the buttons which are part of the titlebar, you do this:

Button b1 = (Button) findViewById(R.id.b1);
        b1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MyApp.this, News.class);

                startActivity(intent);
            }
        });

This has to be done everytime you want to add a titlebar to an activity.

Is there a way to create a class for the titlebar and throw all in there so I dont have to repeat myself on each activity?

emeraldhieu
  • 9,380
  • 19
  • 81
  • 139
Abhishek
  • 1,749
  • 9
  • 27
  • 39

1 Answers1

0

What you most probably trying to do is an action bar. Please take a look at this question What is the equivalent of ActionBar in earlier sdk versions? to find out how to do it for an earlier sdk.

Community
  • 1
  • 1
denis.solonenko
  • 11,645
  • 2
  • 28
  • 23