How to make app icon as up enabled in actionbarsherlock (not the title only icon) like in whats app.
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" />
Answer:
Add the following to your onCreate
method:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
and define the following override method in your activity:
@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
Answer:
My friend, I think this is Android version/build “feature”, because I have two devices, (Nexus S and Nexus 7) (Android 4.1.2 and Android 4.2.2) and I am deploying the app I am developing on both devices, same exact code, on Nexus S the icon is “up”, on Nexus 7 the icon and title are both “up”.
Answer:
make sure your android:minSdkVersion=”11″ which could be seen in the manifest file, Up icon has been included from APK 11. Add the following to your onCreate method For home page put getActionBar().setDisplayHomeAsUpEnabled(false); make sure it false and on other activities you keep it enabled i,e “true”. i have made a small sample plz try the below link which may be help you just import into your work space
Tags: androidandroid