PKlumpp
PKlumpp

Reputation: 5233

Button not showing, Material Theme not working

I am encountering a very strange error in my application. It shows the text of a button, but not the button itself. Here is a screenshot: enter image description here

I then checked the Theme Editor to see what might happen, and what I get in there looks like this: enter image description here

The editor seems to be unable to render Material design correctly, no matter if it is dark or light. When I switch it to Holo for example, everything works fine.

My AndroidStudio is up to date, I have no idea what is going on, but I will provide my styles.xml files here as well:

v21\styles.xml

<resources>>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
        <item name="preferenceStyle">@style/PreferenceThemeOverlay.v14.Material</item>
    </style>

    <style name="MyActionBarTheme" parent="android:Widget.Material.Light.ActionBar">
        <item name="android:background">@color/colorAccent</item>
        <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    </style>

    <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Material.Widget.ActionBar.Title">
        <item name="android:textColor">@color/colorPrimary</item>
    </style>

    <style name="AppTheme" parent="android:Theme.Material.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:colorBackground">@color/background_material_light</item>
        <item name="android:colorPrimary">@color/primary_material_light</item>
        <item name="android:actionBarStyle">@style/MyActionBarTheme</item>
        <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
        <item name="preferenceStyle">@style/PreferenceThemeOverlay.v14.Material</item>
    </style>
</resources>

styles.xml

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:colorBackground">@color/background_material_light</item>
        <item name="android:actionBarStyle">@style/MyActionBarTheme</item>
        <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
        <item name="preferenceStyle">@style/PreferenceThemeOverlay.v14.Material</item>
    </style>


    <style name="MyActionBarTheme" parent="Widget.AppCompat.ActionBar">
        <item name="android:background">@color/colorAccent</item>
        <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    </style>

    <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/colorPrimary</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
        <item name="preferenceStyle">@style/PreferenceThemeOverlay.v14.Material</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

Upvotes: 3

Views: 2065

Answers (1)

PKlumpp
PKlumpp

Reputation: 5233

Ok, I finally found out what was causing the error: My main activity was extending AppCompatActivity (This was generated by Android Studio in an earlier stage). When I changed this to extend FragmentActivity, everything worked like a charm.

This solution solved both the button as well as the theme editor problem. I do not know why theme editor would not show the custom material design when my main application does not extend the correct class, but this small piece of code changed fixed all my issues.

Upvotes: 2

Related Questions