Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action Bar icon as up enabled not the title

How to make app icon as up enabled in actionbarsherlock (not the title only icon) like in whats app.

like image 827
Ravi Avatar asked Apr 25 '13 08:04

Ravi


People also ask

How do I show action bar?

Displaying ActionBar IconsetDisplayShowHomeEnabled(true); getSupportActionBar(). setLogo(R. mipmap. ic_launcher); getSupportActionBar().

What is Android Action Bar?

Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button.


1 Answers

The title is clickable together with the icon since Android 4.2.2. WhatsApp uses a custom view to display a two line title. This disables the title click along the way. You can do it the same way:

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.ab_title);

TextView title = (TextView) findViewById(android.R.id.text1);
title.setText("Title");

/res/layout/ab_title.xml:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="@style/TextAppearance.Sherlock.Widget.ActionBar.Title"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:ellipsize="end"
    android:gravity="center_vertical" />
like image 109
Matthias Robbers Avatar answered Sep 18 '22 18:09

Matthias Robbers