Home>

I need to implement the next ActionBar:
Alt Text

To do this, I wanted to hold such customization:

Public Boolean OnCreateOptionsMenu (Menu Menu) {
    ActionBar ActionBar= GetActionBar ();
    ActionBar.SetDisplayOptions (actionsbar.display_show_custom | actionbar.display_show_home);
    ActionBar.SetcustomView (R.Layout.custom_Menu);
    ActionBar.SetBackGroundDrawable (New ColorDrawable (Color.Gray));
    ActionBar.SethomeButTonEnabled (True);
    ActionBar.SetDisPlayshowHomeEnabled (True);
    ActionBar.SetDisPlayHomeasupenabled (TRUE);
    TextView TextView= (TextView) FindViewByid (R.ID.ActionBar_Title);
    textView.setText ("Title");
    getMenuInflater (). inflate (R.Menu.Menu_Detail_View, Menu);
    Return Super.ONCreateOptionSMenu (Menu);
}

Custom_Menu.xml:

<
? xml version= "1.0" encoding= "UTF-8"? >
≪
LinearLayout
XMLNS: Android= "http://schemas.android.com/apk/res/android"
Android: layout_width= "Match_Parent"
Android: layout_height= "wrap_content"
Android: Layout_Gravity= "Center"
Android: Orientation= "Vertical" >
≪
TextView.
    Android: id= "@ + ID /ActionBar_title"
    Android: layout_width= "wrap_content"
    Android: layout_height= "wrap_content"
    Android: Layout_Gravity= "Center"
    Android: TextStyle= "Bold"
    Android: TextColor= "# FFFFFF"
    Android: TextSize= "18SP"
 /≫

And here is MENU_DETAIL_VIEW.XML -empty

In the end, it turns out that the text in the middle, and the "Home" buttons. How to be? I don't know what to rule ...

  • Answer # 1

    Try to put in LinearLayout value layout_width= "wrap_content" . And then the entire Laiaut takes everything a visible place, and there is a button, but outside the screen.

    Oh, hell, it is brilliant !!!!)

    Stas0n2021-06-22 16:08:07

    and work with ActionBar to transfer to OnCreate

    tim_taller2021-06-22 16:08:07

    @monomi big difference?

    Stas0n2021-06-22 16:08:07

    OnCreateOptionSmenu Designed to work with the menu and initialization Action Bar there is no place

    tim_taller2021-06-22 16:08:07

    @Monomi When working with fragments, change ActionBar will be best in OnCreateOptionsmenu

    Deadkenny2021-06-22 16:08:07