banner



How To Change The Titlebar Of An Activity In Android Studio

Update: Latest ActionBar (Title) pattern:

FYI, ActionBar was introduced in API Level 11. ActionBar is a window feature at the pinnacle of the Activity that may display the action title, navigation modes, and other interactive items like search.

I exactly remember about customizing title bar and making information technology consistent through the awarding. So I can make a comparison with the earlier days and can list some of the advantages of using ActionBar:

  1. It offers your users a familiar interface across applications that the organisation gracefully adapts for different screen configurations.
  2. Developers don't need to write much lawmaking for displaying the Activity Championship, icons and navigation modes because ActionBar is already set up with top level abstraction.

For example:

enter image description here

enter image description here

=> Normal way,

          getActionBar().setTitle("Howdy earth App");    getSupportActionBar().setTitle("How-do-you-do world App");  // provide compatibility to all the versions                  

=> Customizing Activity Bar,

For example:

          @Override public void setActionBar(String heading) {     // TODO Auto-generated method stub      com.actionbarsherlock.app.ActionBar actionBar = getSupportActionBar();     actionBar.setHomeButtonEnabled(truthful);     actionBar.setDisplayHomeAsUpEnabled(false);     actionBar.setDisplayShowHomeEnabled(false);     actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.title_bar_gray)));     actionBar.setTitle(heading);     actionBar.bear witness();  }                  

Styling the Action Bar:

The ActionBar provides you with basic and familiar looks, navigation modes and other quick actions to perform. But that doesn't hateful it looks the same in every app. You tin can customize it as per your UI and design requirements. Y'all just accept to ascertain and write styles and themes.

Read more at: Styling the Action Bar

And if yous want to generate styles for ActionBar then this Fashion Generator tool tin aid you out.

=================================================================================

Old: Before days:

=> Normal way,

you can Alter the Title of each screen (i.e. Action) past setting their Android:label

                      <activity android:name=".Hello_World"                   android:label="This is the Howdy Globe Application">    </activeness>                  

=> Custom - Championship - bar


But if you want to Customize title-bar in your own mode, i.e. Want to put Prototype icon and custom-text , then the following lawmaking works for me:

main.xml

          <?xml version="ane.0" encoding="utf-eight"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"/>                  

titlebar.xml

          <?xml version="1.0" encoding="utf-eight"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="400dp"    android:layout_height="fill_parent"   android:orientation="horizontal">  <ImageView android:id="@+id/ImageView01"              android:layout_width="57dp"              android:layout_height="wrap_content"             android:background="@drawable/icon1"/>  <TextView     android:id="@+id/myTitle"    android:text="This is my new title"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:textColor="@color/titletextcolor"    /> </LinearLayout>                  

TitleBar.java

          public course TitleBar extends Action {      @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         concluding boolean customTitleSupported =                  requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);         setContentView(R.layout.master);         if (customTitleSupported) {             getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,                 R.layout.titlebar);         }         final TextView myTitleText = (TextView) findViewById(R.id.myTitle);         if (myTitleText != zilch) {             myTitleText.setText("NEW TITLE");             // user can also gear up color using "Color" and then             // "Color value constant"             // myTitleText.setBackgroundColor(Color.GREEN);         }     } }                  

strings.xml

The strings.xml file is defined under the values binder.

          <?xml version="1.0" encoding="utf-8"?> <resources>     <cord name="hi">Hello World, Set_Text_TitleBar!</string>     <string name="app_name">Set_Text_TitleBar</string>     <colour name="titlebackgroundcolor">#3232CD</color>     <color proper noun="titletextcolor">#FFFF00</color> </resource>                  

Source: https://stackoverflow.com/questions/3438276/how-to-change-the-text-on-the-action-bar

Posted by: thorntonxvier1937.blogspot.com

0 Response to "How To Change The Titlebar Of An Activity In Android Studio"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel