First, I want to change the color Menu Item color, I used this:
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/search_toolbar"
style="@style/Widget.CustomActionBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/light_background"
app:theme="@style/SearchToolbarTheme" />
<style name="SearchToolbarTheme" parent="Widget.AppCompat.Toolbar">
<item name="colorControlNormal">@color/slate_grey</item> <!-- Arrow color -->
<item name="colorControlHighlight">@color/grey</item> <!-- Ripple effect color -->
<item name="colorPrimaryDark">@color/dark_blue</item> <!-- Status bar color -->
<item name="colorPrimary">@color/dark_blue</item> <!-- Status bar color -->
</style>
And it works well!
Then, I want to custom Toolbar:
public class SearchToolbar extends Toolbar {
public SearchToolbar(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}
public SearchToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {}
Change the xml file to
<com.abc.searchtoolbar.SearchToolbar xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/search_toolbar"
style="@style/Widget.CustomActionBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/light_background"
app:theme="@style/SearchToolbarTheme" />
After that, the app:theme doesn't work anymore.
How can I keep the app:theme attribute in my custom view when I extends Toolbar?