SearchView and toolbars - android

I want a menu item in my toolbar when clicked to act like a SearchView. I tried this, but the icon was still the default SearchView icon...
<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=".MainActivity">
<item
android:id="#+id/action_edit_courses"
android:title="#string/action_edit"
android:orderInCategory="100"
android:icon="#android:drawable/ic_menu_edit"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always" />
<item
android:id="#+id/action_delete_courses"
android:title="#string/action_delete"
android:orderInCategory="100"
android:icon="#android:drawable/ic_menu_delete"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="ifRoom" />
Please I don't know how to get through with it... Thank you in advance

Related

actionbar on AndroidTV not focusable?

I'm using AppCompatActivity with theme Theme.MaterialComponents.DayNight.DarkActionBar
In AndroidTV I can't have the focus on the ActionBar menu buttons I added (to the right) using D-Pad :
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".home.HomeActivity">
<group android:checkableBehavior="single">
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_search"
android:orderInCategory="2"
android:title="#string/search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="collapseActionView|ifRoom" />
<item
android:id="#+id/action_refresh"
android:icon="#drawable/ic_refresh"
android:orderInCategory="1"
android:title="#string/refresh"
app:showAsAction="collapseActionView|ifRoom" />
</group>
</menu>
Is there any solution ?
Thanks in advance for help !

How does android action bar work?

<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=".MainActivity">
<item
android:id="#+id/action_settings"
android:title="Settings"
android:orderInCategory="100"
app:showAsAction="never" />
<item android:id="#+id/action_search"
android:orderInCategory="200"
android:title="Search"
android:icon="#android:drawable/ic_search_category_default"
app:showAsAction="ifRoom" />
<item android:id="#+id/action_user"
android:orderInCategory="300"
android:title="User"
android:icon="#android:drawable/ic_dialog_info"
app:showAsAction="ifRoom" />
</menu>
I'm experimenting with android action bar and I'm confused how the settings and other actions are added to my action bar from the menu.
How did android determine that the first item in my list is to be added the three dot menu?
Because you asked android to not show it as action, like this:
app:showAsAction="never"
while for other items you show them when there is enough space to show:
app:showAsAction="ifRoom"

align menu item to the left?

How does one go about changing the orientation of a menu item? This is what my current menu.xml looks like:
<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=".MainActivity">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
<item android:id="#+id/chat_delete"
android:title="delete"
android:icon="#drawable/ic_chevron_left"
app:showAsAction="always"
android:orderInCategory="1"
/>
However, I want to have the chat_delete element shifted all the way to the left. Is this possible through xml?

Hiding all icons when user touches to search

I want to hide all icons in action bar when user touches the search icon. But one icon is not hiding.
My xml:
<?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_white_36dp"
android:title="Ara"
app:showAsAction="always"
android:iconifiedByDefault="true"
app:actionViewClass="android.widget.SearchView"/>
<item android:id="#+id/action_shuffle"
android:icon="#drawable/ic_autorenew_white_24dp"
android:title="Karıştır"
app:showAsAction="always" />
<item android:id="#+id/action_premium"
android:icon="#drawable/ic_star_white_24dp"
android:title="Premium"
app:showAsAction="always" />
<item android:id="#+id/action_favorites"
android:icon="#drawable/ic_people_white_24dp"
android:title="Takip Listesi"
app:showAsAction="always" />
<item android:id="#+id/action_settings"
android:icon="#drawable/ic_settings_white_24dp"
android:title="Settings"
app:showAsAction="always" />
<item android:id="#+id/action_fullpicture"
android:icon="#drawable/ic_action_picture"
app:showAsAction="always"
android:visible="false" />
</menu>
Before:
After:
How can I hide action_shuffle too? Other icons automaticly hiding I didn't do anything special.
You should change the app:showAsAction = "always" to app:showAsAction = "ifRoom".
Other way could be this answer, take a look.

SearchView in Actionbar Appcompat

In my application, I am using Theme.AppCompat.Light.DarkActionBar but I am facing a weird problem. I have created SearchView in ActionBar and has set its property app:showAsAction="collapseActionView|ifRoom"
but the SearchView is not expanded or collapsed on touch.
menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/search"
android:title="#string/search"
android:icon="#android:drawable/ic_menu_search"
app:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.support.v7.widget.SearchView" />
</menu>
I have tried different solutions but none worked. Any idea?
try to change
android:actionViewClass="android.support.v7.widget.SearchView"
by
app:actionViewClass="android.support.v7.widget.SearchView"
This worked for me
<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.ipartie.views.activities.HomeActivity">
<item
android:id="#+id/search"
android:title="#string/search"
android:icon="#drawable/abc_ic_search_api_mtrl_alpha"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView"/>
</menu>

Categories

Resources