Hello i want to change 4 to an help icon or if this is not possible, hide it and add a help icon to 3.
I dont want it to be a dropdown menu, i just want a clickable icon.
And is there a way to hide/show it from within a fragment?
I tried to change res/menu/menu_main3.xml but nothing happened.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.test.test.Main3Activity">
<item
android:id="#+id/action_help"
android:icon="#drawable/ic_help_outline_black_24dp"
android:orderInCategory="100"
app:showAsAction="always"/>
If you want to do so, you have to implement your custom Toolbar, which is just a ViewGroup. So you will be able to add and adjust any views (in this case it would be ImageButton)
Related
I've a menu.xml file, where I've:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".main.MainActivity"
tools:ignore="..">
<item android:id="#+id/test_button"
android:icon="#drawable/search"
android:title="#string/.."
app:showAsAction="always|collapseActionView" />
</menu>
Any item I add here is being shown on the right side.
There's also default "back" button which I can easily hide/disable by mActionBar.setDisplayHomeAsUpEnabled(false);. The position of "back" button is precisely what I want, just "custom" button. This should be only possible when entering specific Fragment, let's say Fragment A.
Activity is extending AppCompatActivity.
How can I do this? What is the best way (cleanest) of doing this? An example would be great!
Yes it is possible you have to create your own custom view for action bar and set it this way
mActionBar.setCustomView(customView);
mActionBar.setDisplayShowCustomEnabled(true);
I have an application without an appbar. Now I want to put 3 Buttons into a menu. I have seen the option to create a toolbar and then add the items programmaticlly. But first I would prefer not to have a bar but just the menu.
I know that that isn´t really important because I can make the bar transparent.
And Second I really don´t want to add the items programmatically. (But defigned in xml.) Is this possible, are there better ways and how can I do it?
If "By the menu" you mean, the overflow menu that exists in the app bar then you can not just the add the menu that way. The app bar or toolbar has to be there to contain that overflow menu. But for giving that sort of effect as you also mentioned you can have the toolbar transparent or you can look into the PopUpMenu, http://developer.android.com/guide/topics/ui/menus.html,
this way you can hide your app bar and can give a separate button which will call PopUpMenu, its going to give you same overflow menu effect.
Regarding your 2nd requirement of putting menu in xml, if i am getting it correct you can have your menu defined like this,
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/phone"
android:title="#string/phone"
android:icon="#drawable/phone"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/computer"
android:title="#string/computer"
android:icon="#drawable/computer"
android:showAsAction="ifRoom|withText"
/>
</menu>
You need your CSS anymets revised.
Please consider this codings:
style {template.css}
I think you'll find those are the exact answer.
I have one activity with action bar. Action bar contains search view. I don't want that back button which appears when search view is clicked. Is it possible to remove it or hide it? That back button is not visible until I click the search view. By the way the following line of code doesn't help.
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
Menu resource
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_search"
android:title=""
app:showAsAction="always|collapseActionView"
android:icon="#drawable/ic_action_search"
app:actionViewClass="android.support.v7.widget.SearchView" />
</menu>
I have been dealing with a similar issue. To simply remove the arrow, I changed app:showAsAction="always|collapseActionView" to app:showAsAction="always".
However, now I have a blank space instead of the arrow, which is an issue I have yet to resolve.
We had the same problem and fixed it by setting the
app:collapseIcon
attribute in the toolbar.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbarHeight"
app:collapseIcon="#drawable/collapseBackIcon" />
I've set up a simple menu with one position like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="#+id/action_language" android:title="#string/language"
android:orderInCategory="100" />
</menu>
using
Theme.AppCompat.Light.DarkActionBar
style. When I click the three dots the menu position appears instead of the icon, not below it? Is there any way to make it appear under the icon, not 'on' it?
Actually you can't do anything with this icon, but you can create menu item with android:actionLayout="#layout/custom_lauout". Then you can create Popup Window, which allows such positioning. In popupWindow you will show all items that must show under "three dots item".
Here rea a few links which can help you: http://developer.android.com/reference/android/widget/PopupWindow.html
https://stackoverflow.com/a/23516493/3864698
I'm trying to display a progress bar instead of a refresh menu item in the action bar. However, when I currently press the refresh button, it disappears, but the progress bar replaces the action bar title, instead of appearing where the refresh button was.
These are my two .xml files:
The menu item:
<item android:id="#+id/menu_refresh"
android:icon="#drawable/ic_menu_refresh"
android:visible="true"
android:orderInCategory="0"
android:showAsAction="ifRoom|collapseActionView"
android:actionLayout="#layout/action_progress_bar"
android:title="#string/refresh"
android:titleCondensed="#string/refresh"/>
The progress bar layout:
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="32dp"
android:layout_height="32dp" >
</ProgressBar>
I found out what the problem is. In order for the progress bar to appear instead of the menu item, it must not have the collapseActionView flag. Removing it, and moving the logic to the code (along with using the easy setActionView method), did the trick
This is a default actionLayout behaviour, and AFAIK you can't change it. Instead you could try something like handling the button click and replacing the bar item from code.
UPDATE:
Take a look at the ActionBarCompat sample project. (New Project/Android Sample Project).