Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Update: Latest ActionBar (Title) pattern:</h2> <p>FYI, <a href="http://developer.android.com/reference/android/app/ActionBar.html" rel="noreferrer">ActionBar</a> was introduced in API Level 11. ActionBar is a window feature at the top of the Activity that may display the <strong>activity title</strong>, navigation modes, and other interactive items like search.</p> <p>I exactly remember about customizing title bar and making it consistent through the application. So I can make a comparison with the earlier days and can list some of the advantages of using ActionBar:</p> <ol> <li>It offers your users a familiar interface across applications that the system gracefully adapts for different screen configurations.</li> <li>Developers don't need to write much code for displaying the Activity Title, icons and navigation modes because ActionBar is already ready with top level abstraction.</li> </ol> <p>For example:</p> <p><img src="https://i.stack.imgur.com/a8Np0.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/gv12y.png" alt="enter image description here"></p> <h2>=> Normal way,</h2> <pre><code>getActionBar().setTitle("Hello world App"); getSupportActionBar().setTitle("Hello world App"); // provide compatibility to all the versions </code></pre> <h2>=> Customizing Action Bar,</h2> <p>For example:</p> <pre><code>@Override public void setActionBar(String heading) { // TODO Auto-generated method stub com.actionbarsherlock.app.ActionBar actionBar = getSupportActionBar(); actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayShowHomeEnabled(false); actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.title_bar_gray))); actionBar.setTitle(heading); actionBar.show(); } </code></pre> <h2>Styling the Action Bar:</h2> <p>The ActionBar provides you with basic and familiar looks, navigation modes and other quick actions to perform. But that doesn't mean it looks the same in every app. You can customize it as per your UI and design requirements. You just have to define and write styles and themes.</p> <p>Read more at: <a href="https://developer.android.com/training/basics/actionbar/styling.html" rel="noreferrer">Styling the Action Bar</a></p> <p>And if you want to generate styles for ActionBar then this <a href="http://jgilfelt.github.io/android-actionbarstylegenerator/" rel="noreferrer"><strong>Style Generator</strong></a> tool can help you out.</p> <p>=================================================================================</p> <h2>Old: Earlier days:</h2> <h2>=> Normal way,</h2> <p>you can Change the Title of each screen (i.e. Activity) by setting their <strong><code>Android:label</code></strong></p> <pre><code> &lt;activity android:name=".Hello_World" android:label="This is the Hello World Application"&gt; &lt;/activity&gt; </code></pre> <h2>=> Custom - Title - bar</h2> <hr> <p>But if you want to Customize title-bar in your own way, i.e. <strong><em><code>Want to put Image icon and custom-text</code></em></strong>, then the following code works for me:</p> <h2>main.xml</h2> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"/&gt; </code></pre> <h2>titlebar.xml</h2> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="400dp" android:layout_height="fill_parent" android:orientation="horizontal"&gt; &lt;ImageView android:id="@+id/ImageView01" android:layout_width="57dp" android:layout_height="wrap_content" android:background="@drawable/icon1"/&gt; &lt;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" /&gt; &lt;/LinearLayout&gt; </code></pre> <h2>TitleBar.java</h2> <pre><code>public class TitleBar extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); if (customTitleSupported) { getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar); } final TextView myTitleText = (TextView) findViewById(R.id.myTitle); if (myTitleText != null) { myTitleText.setText("NEW TITLE"); // user can also set color using "Color" and then // "Color value constant" // myTitleText.setBackgroundColor(Color.GREEN); } } } </code></pre> <h2>strings.xml</h2> <p>The strings.xml file is defined under the <strong><code>values</code></strong> folder.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string name="hello"&gt;Hello World, Set_Text_TitleBar!&lt;/string&gt; &lt;string name="app_name"&gt;Set_Text_TitleBar&lt;/string&gt; &lt;color name="titlebackgroundcolor"&gt;#3232CD&lt;/color&gt; &lt;color name="titletextcolor"&gt;#FFFF00&lt;/color&gt; &lt;/resources&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload