Action Bar icon as up enabled not the title

后端 未结 4 988
逝去的感伤
逝去的感伤 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: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:

    
    

提交回复
热议问题