Android change top menu - android

I don’t know what the real name of this is, but I want to change the top menu for an image or button. Someone can tell me what the name is and how do that in my android aplication?.
something like it!!!

in your menu xml add this in the item tag android:icon="#drawable/youricon"
app:showAsAction="always"

If you mean the custom text, you can add custom vews in your toolbar. The toolbar is just a viewgroup where you can add views inside. See this as an example.
If you mean to add a custom image instead of the back arrow, you can switch it with the toolbar.setNavigationIcon(Drawable drawable) method.
If you want to display the default arrow, then try with this (after setting the toolbar).
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}

Related

How to set text on bottom of logo actionbar android

enter image description here
How to i print text on bottom of Action bar logo
<item android:title="Customer Inquiry"
android:id="#+id/customer_inquiry"
app:showAsAction="always|withText"
android:icon="#drawable/customer_inqury"/>
i set text but its not visible...!
there is no such option for MenuItem, by design these items don't and shouldn't have any text. if you really need those labels you need to write own drawing class and use app:actionLayout or even whole custom Toolbar set for Activity with setSupportActionBar(..) in Activity

How To Change Included Toolbar Title And Drawable?

I have a hard time finding on how to change the Toolbar title and it's drawable in every and each Activity.
There is something on Android Documentation that states that to minimize APK size. It is recommended to re-used components.
I create a separate layout, and <include layout=""/> to each of my Activities like Help, About , and etc. I also put android:label="Title" on Manifest File.
Toolbar.xml
My Main:
How do I access this included Toolbar DRAWABLE and TITLE in my Activities ?
Update: I removed ActionBar .
You are using Toolbar. So no need to do anything with ActionBar. Just set your Toolbar as supportActionBar. Then set title and icon to your Toolbar.
Use the below code:
mToolbar = (Toolbar)findViewById(R.id.Toolbar);
setSupportActionBar(mToolbar);
setTitle("About");
getSupportActionBar.setIcon(R.id.ic_arrow_back_black_24dp);
And, Remove all your mActionBar codes. Hope this helps.
well you set the support action to your custom toolbar,yet you ignore it and use mActionBar, see where i am going with this? setIcon , and setTitle should all be called relative to your custom toolbar.

setHomeAsUpIndicator is not take effect when use setDisplayShowHomeEnabled(false)

I want to change ActionBar Indicator(the left arrow) and don't want to display the logo
so i setDisplayShowHomeEnabled(false) to make the logo is invisiable,
and setHomeAsUpIndicator(my image) to change the indicator,
but it doesn't work
One way is to not call setDisplayShowHomeEnabled(false). Instead use findViewById() to get the home View, and directly set it to GONE.
View homeView = findViewById(android.R.id.home);
homeView.setVisibility(View.GONE);
Why don't you do this in your Manifest.xml file
android:logo=#null or android:icon=#null

Android - ActionBar - How to get color of hold event

There's a way to know the color of hold event on action bar? Like image below:
The theme is Theme.AppCompat.Light
I just want the color value... but, how?
you can achieve it by using custom action bar.
Add in onCreate methode:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
// create xml in layout and inflate into view.
View v = getLayoutInflator().inflate(R.layout.search, null);
// here you can find id add listener on add button.
Button addBtn = (Button)v.findViewById(R.id.addBtn);
addBtn.setonClickListener(this);
//Now add view in your action bar.
actionBar.setCustomView(v);
I think it will help.
This color is defined in xml file. you can create your own style by using:
actionbar style generator
or you can see the source code of
Theme.AppCompat
in summary this value is set statically and you can find it without needing to get it at the runtime because it is what you have styled.
for other part of your app you can create theme with
android holo colors
if you want the color value here it is:
The color is

how to hide up button in actionbar

I would like to do an edit mode, in the style of the tablet gmail app.
If the user presses the edit button on the actionbar, than I would like to show him/her an action view, that has a done button on the left side, and a delete button on the right.
I have an example that works without actionbarsherlock here:
https://code.google.com/p/romannurik-code/source/browse/misc/donediscard
I would like to stick to actionbarsherlock, for compatibility reasons.
This is the way I solved it in onCreateOptionsMenu:
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.white));
getSupportActionBar().setIcon(R.drawable.white);
for (int i = 0; i < menu.size(); i++) {
menu.getItem(i).setVisible(false); }
getSupportActionBar().setDisplayHomeAsUpEnabled(false); does nothing, so I had to set the home icon to a white 1x1 pixel drawable.
I also had to set the background color of the actionbar, as the actionview's background color. If I had not, than the 1x1 home icon would have padding around it, and the original background color would be visible around the white home button.
Anyone got a better solution for this?
edit:
I also had to change the style:
<style name="Theme.Styled" parent="Theme.Sherlock.Light">
<item name="android:homeAsUpIndicator">#drawable/white</item>
<item name="homeAsUpIndicator">#drawable/white</item>
</style>
Also..settings android:homeAsUpIndicator increased my min api level from 8 to 11 which is also an issue.
If you're on API level 14 or above and are not using ActionbarSherlock, this code in onCreateOptionsMenu will disable the up button, remove the left caret, and remove the icon:
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(false); // disable the button
actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
actionBar.setDisplayShowHomeEnabled(false); // remove the icon
}
You were almost there. To hide the icon/logo completely, use setDisplayShowHomeEnabled(false). The call you're using just removes the little arrow that indicates that the icon acts as an "up" button also.
This worked for me, though its a slight change in the above mentioned solution
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(false); // disable the button
actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
actionBar.setDisplayShowHomeEnabled(false); // remove the icon
}
Though it's an older post, I would like to share an answer which worked for me.
To hide the UP button in actionbar, use the following in OnCreateOptionsMenu:
if (getSupportActionBar() !=
getSupportActionBar().hide();
}
To remove the UP button in actionbar, use the following in OnCreateOptionsMenu:
if (getSupportActionBar() !=
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
I hope it will help newbies.

Categories

Resources