I tried several solutions here in stackoverflow, but none worked for me.
I have the icon in the toolbar and it expands when clicked and opens the activity to be done the search. Codes below:
XML 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/item_search"
android:orderInCategory="200"
android:title="@string/search"
android:icon="@drawable/ic_search_24dp"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView"
android:iconifiedByDefault="false" />
</menu>
Activity Code:
class HomeActivity : LoggedActivity<ViewHomeBinding, HomeViewModel>(), HomeView {
// ATTRIBUTES
private var pagerAdapter: HomePagerAdapter? = null
// BASE METHODS
override fun onInject(component: LoggedActivityComponent) = component.inject(this)
override val contentView = R.layout.view_home
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_home, menu)
return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
R.id.item_search -> {
startActivity(Intent(this, SearchActivity::class.java))
true
}
else -> super.onOptionsItemSelected(item)
}
I wish it would always be expanded. And of the white color, since it expands green, is it possible? Thank you
I tried this in XML; android: iconifiedByDefault = "false" app: iconifiedByDefault = "false"
EDIT:
Toobar XML in HomeActivity
<data>
<variable
name="viewModel"
type="com.plugapps.zuk.viewmodel.HomeViewModel"/>
</data>
<android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>