How to add buttons like refresh and search in ToolBar in Android?

后端 未结 4 1732
情书的邮戳
情书的邮戳 2020-12-12 18:50

\"enter

I have made a ToolBar, but when I add menu items in menu.xml it always shows a

相关标签:
4条回答
  • 2020-12-12 19:22

    Add this line at the top:

    "xmlns:app="http://schemas.android.com/apk/res-auto"

    and then use:

    app:showasaction="ifroom"

    0 讨论(0)
  • 2020-12-12 19:22

    To control the location of the title you may want to set a custom font as explained here (by twaddington): Link

    Then to relocate the position of the text, in updateMeasureState() you would add p.baselineShift += (int) (p.ascent() * R); Similarly in updateDrawState() add tp.baselineShift += (int) (tp.ascent() * R); Where R is double between -1 and 1.

    0 讨论(0)
  • 2020-12-12 19:27

    Try to do this:

    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    

    and if you made your custom toolbar (which i presume you did) then you can use the simplest way possible to do this:

    toolbarTitle = (TextView)findViewById(R.id.toolbar_title);
    toolbarSubTitle = (TextView)findViewById(R.id.toolbar_subtitle);
    toolbarTitle.setText("Title");
    toolbarSubTitle.setText("Subtitle");
    

    Same goes for any other views you put in your toolbar. Hope it helps.

    0 讨论(0)
  • 2020-12-12 19:47

    OK, I got the icons because I wrote in menu.xml android:showAsAction="ifRoom" instead of app:showAsAction="ifRoom" since i am using v7 library.

    However the title is coming at center of extended toolbar. How to make it appear at the top?

    0 讨论(0)
提交回复
热议问题