Action Bar icon as up enabled not the title

后端 未结 4 986
逝去的感伤
逝去的感伤 2021-02-04 15:43

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

相关标签:
4条回答
  • 2021-02-04 16:15

    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".

    0 讨论(0)
  • 2021-02-04 16:17

    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;
    }
    
    0 讨论(0)
  • 2021-02-04 16:24

    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

    http://www.mediafire.com/?hktdvts7yyduwv1

    0 讨论(0)
  • 2021-02-04 16:25

    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" />
    
    0 讨论(0)
提交回复
热议问题