Reputation: 4639
I want make new theme for my app (one theme before < v21
and one theme >=v21
and higher).
This is code from Activity
:
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.DriverNotesAppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tool_bar_test);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
XML-layout toolbar:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:popupTheme="@style/DriverNotesAppTheme"
app:theme="@style/DriverNotesAppTheme">
This is theme before v21
:
<style name="DriverNotesAppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- customize the color palette -->
<item name="colorPrimary">@color/material_bg</item>
<item name="colorPrimaryDark">@color/status_bar</item>
<item name="colorAccent">@color/edittext_primary</item>
<item name="android:windowBackground">@color/light_blue</item>
</style>
This is theme for v21
and higher:
<style name="DriverNotesAppTheme" parent="android:Theme.Material">
<!-- customize the color palette -->
<item name="colorPrimary">@color/material_bg</item>
<item name="colorPrimaryDark">@color/status_bar</item>
<item name="colorAccent">@color/edittext_primary</item>
<item name="android:windowBackground">@color/light_blue</item>
</style>
And this is screenshots:
v21
and higher;
before v21
Upvotes: 3
Views: 163
Reputation: 6908
Code Corrected
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tool_bar_test);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
Set The Theme in your ToolBar
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:popupTheme="@style/<Your Theme Name>"
app:theme="@style/<Your Theme Name>"/>
Upvotes: 3