Artem
Artem

Reputation: 4639

Android theme error's

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: enter image description here v21 and higher;

enter image description here

before v21

And colors from resources: enter image description here

Upvotes: 3

Views: 163

Answers (1)

johnrao07
johnrao07

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

Related Questions