Can you remove back button after search view has been clicked (expanded) - android

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" />

Related

How to prevent ActionBar SearchView button from disappearing

I have been having a lot of trouble trying to fix this one and couldn't find any solutions for this anywhere.
Currently I have the following ActionBar option menu
<?xml version="1.0" encoding="utf-8"?>
<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:icon="#drawable/ic_search"
android:title="#string/menu_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
<item
android:id="#+id/action_sort_by"
android:title="#string/sort_by"
app:showAsAction="never" />
<item
android:id="#+id/action_refresh"
android:title="#string/action_refresh"
app:showAsAction="never" />
</menu>
And everything works perfectly fine except if the options menu is opened while the search option is also opened:
The target layout as expected
The search option opened
This is the step that causes the problem, as you can see the Search option is now in the menu
Because of the previous step the search button is gone when closing the menu and the search option
If I don't open the options menu while the search option is also opened then everything works perfectly well, however this is something that cannot be expected for users to do and they might open the menu with the search options opened, leading to the search icon to disappear, resulting in a very problematic user experience.
How can I fix this, how can I prevent this problem from happening while keeping that same layout? Search icon visible, everything else in the 3 dots options menu.
To always show the search icon, simple change app:showAsAction="ifRoom|collapseActionView" to app:showAsAction="always|collapseActionView"

Change menu action item position - to the left side

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);

Android Action Bar replace context menu icon

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)

Toolbar Overflow button onClick startactivity

How can I start new activity on click of the Android toolbar's overflow button click. I don't want the dropdown to appear since I only have one item, rather directly change the activity.
Add this line in your menu_item.xml file:
app:showAsAction="always"
menu_item.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_github"
android:title="#string/title_github"
android:icon="#drawable/ic_github"
app:showAsAction="always" />
</menu>

android fragment activity menu

I have a class that extends FragmentActivity. No I want to show my menu items at the top of the screen like in actionbar. How can I do this ?
I have created the menu items and they are visible hen the hardware button for menu is pressesd but I want to sho them at the top of the screen.
Basically, this happens in devices with physical menu button. In devices without that button, all options are displayed in the action bar.
You can force a menu item to be displayed in the action bar by addind "showAlways" to the item that you want.
showAsAction=“always”
An small example
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
android:showAsAction="always" />
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:showAsAction="always" />
</menu>
You must need to ensure that you have enough space for the menu items.
To ensure that I'll have enough space, I use to create a menu with only one item. Then, inside this item, I create another menu. This way, only one button is displayed and all items appear in a floating pop up menu. The main idea is below:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/overflow_item"
android:icon="#drawable/ic_overflow_icon"
android:title="#string/options"
android:showAsAction="always" />
<menu>
<item android:id="#+id/action_clear"
android:title="#string/clear"
android:showAsAction="always" />
</menu>
</menu>

Categories

Resources