As the title suggests, I want to put some text in the action bar. Firstly, here's a mockup (in Paint!) of what I'm imagining:
I'm really struggling with this. In my activity I put:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_screen, menu);
return true;
}
And in the menu folder I put main_screen.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/user_level"
android:title="Administrator"
android:showAsAction="withText" />
</menu>
So I have 2 questions:
Question 1
Why at the very least the solution above doesn't show the text Administrator
Question 2
Once it's showing the text, how do I make it appear like a label (with the grey background and the rounded corners, etc)?
Thank you for your help.
custom menu item is what you need for your second question.
first you need to make custom layout for your menu item.
cust_menu.xml
for making rounded grey square background you need to make custom shape file and set it to your
TextView
background.my_shape.xml
now your menu item will go like this.
main.xml
and in java class simply do this.
let me know if any doubts.
for more information visit this
EDIT :
you can access your
TextView
this way.happy coding.
You can try adding below code in your menu item:
50
is just a random number.You can configure the ActionBar styles and properties by creating ActionBar theme styles.
Read more at: Custom ActionBar Styles
Question 1
You have to use the app namespace.
Question 2
You cannot use menu to do that. What you can do is to use
AppBarLayout
.