Button not showing, Material Theme not working - android

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:
I then checked the Theme Editor to see what might happen, and what I get in there looks like this:
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>

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.

Related

how to bring the icons closer?

I am having my app bar with three icons on it. The space between them looks quite high. How to get them closer
the following is my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowDisablePreview">true</item>
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="actionOverflowMenuStyle">#style/OverflowMenu</item>
</style>
<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<!-- Required for pre-Lollipop. -->
<item name="overlapAnchor">false</item>
</style>
<style name="AppTheme.NoActionBar">
<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>
Use this theme changing what you think needs to be changed but definitely experiment with the width and height values to find the ones that suit your needs.
<style name="MyTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="colorControlNormal">#android:color/black</item>
<item name="android:actionButtonStyle">#style/myActionButtonStyle</item>
<item name="actionButtonStyle">#style/myActionButtonStyle</item>
</style>
<style name="myActionButtonStyle" parent="Widget.AppCompat.ActionButton">
<item name="android:width">80dp</item>
<item name="android:height">80dp</item>
</style>

Auto background color is black even when I create a new Activity

I don't know if is related with git but after committing my project using git, every Activity's background color is changed even when I create a new Activity.
Why?
My style file
<resources>
<!-- 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="drawerArrowStyle">#style/MyDrawerArrowToggle</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyDrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">#color/toolbar_text_color</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">#color/textColor</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"></style>
</resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.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="drawerArrowStyle">#style/MyDrawerArrowToggle</item>
</style>
I changed "Theme.AppCompat.NoActionBar" to "Theme.AppCompat.Light.NoActionBar".
It is worked.Thanks everyone....
Here is the mistake you are using dark theme
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">#color/textColor</item>

how can I change toolbar searchView drop down menu theme to be light in android app

i have developed an android app with search view on action bar
but the suggestion drop down menu items are dark.
is there a way i can turn the drop down menu to light ?
this is my style.xml file
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<!--<item name="android:dropDownListViewStyle">#android:style/Widget.DeviceDefault.Light.ListView.DropDown</item>-->
<item name="colorAccent">#color/colorAccent</item>
<item name="android:actionBarWidgetTheme">#style/Widget.AppCompat.Light.ActionBar</item>
<item name="android:popupMenuStyle">#android:style/Widget.Holo.Light.PopupMenu</item>
<!--<item name="android:dropDownListViewStyle">#android:style/Theme.Light</item>-->
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.ButtonBase" parent="Widget.AppCompat.Button.Colored">
<item name="android:paddingTop">12dip</item>
<item name="android:paddingBottom">12dip</item>
<item name="android:textSize">16.9sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="AppTheme.ButtonPrimary" parent="AppTheme.ButtonBase">
<item name="colorButtonNormal">#color/buttonPrimary</item>
<item name="android:textColor">#color/textLight</item>
</style>
<style name="MineCustomTabText" parent="TextAppearance.Design.Tab">
<item name="android:textSize">18sp</item>
</style>
<style name="AppTheme.ButtonSecondary" parent="AppTheme.ButtonBase">
<item name="android:textColor">#color/textLight</item>
</style>
Just comment out your style code. for below attribute in your code.
android:dropDownListViewStyle
Now build and run your app again.
It will help you.

Can't remove shadow that's above the action bar

Note: I'm rather new to Android development, so bear with me...
I recently created a new project in Android Studio using the Navigation Drawer activity layout. Everything runs correctly, however I would like to remove the shadow that's above the action bar.
I've tried applying this solution, but it didn't seem to solve my issue.
Here are my styles.xml files:
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>
</style>
</resources>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<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>
Any help would be greatly appreciated!
Thank you.
For some reason, this did not work for as well:
<item name="android:elevation">0dp</item>
and:
<item name="android:windowContentOverlay">#null</item>
I am currently using, for ActionBar:
this.getSupportActionBar().setElevation(0);

getSupportActionBar() throws NPE when using appcompat-v7 22.2.1 or newer

I have an app using the below main theme in values/styles.xml
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Example</item>
<item name="actionBarTabTextStyle">#style/tabtextcolor</item>
<item name="colorPrimary">#color/primary_blue</item>
<item name="colorPrimaryDark">#color/primary_darker_blue</item>
<item name="android:windowContentOverlay">#null</item>
<item name="colorAccent">#color/primary_blue</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">false</item>
<item name="background">#color/primary_blue</item>
<item name="backgroundStacked">#android:color/white</item>
<item name="backgroundSplit">#color/primary_blue</item>
<item name="icon">#android:color/transparent</item>
<item name="popupMenuStyle">#style/PopupMenu.Example</item>
<item name="android:titleTextStyle">#style/Widget.Carrental.TitleTextStyle</item>
<item name="titleTextStyle">#style/Widget.Carrental.TitleTextStyle</item>
</style>
<style name="Widget.Carrental.TitleTextStyle" parent="#android:style/Widget.TextView">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:alpha">1</item>
</style>
<style name="tabtextcolor" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#android:color/black</item>
</style>
<style name="ActionBarTabStyle.Example" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_example</item>
</style>
All this works fine when I use appcompat-v7 22.2.1 on Kitkat and Lollipop.
I had to add a compile dependency, which had the below theme in values/style.xml
<style name="AppTheme.Transparent" parent="AppTheme.Transparent.Base" />
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowContentOverlay">#null</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/accent</item>
</style>
<style name="AppTheme.Transparent.Base" parent="AppTheme.Base">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
</style>
And these in values-21/styles.xml
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">#android:transition/move</item>
<item name="android:windowSharedElementExitTransition">#android:transition/move</item>
</style>
<style name="AppTheme.Transparent" parent="AppTheme.Transparent.Base">
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
Now when I try to run my app, it fails with NPE in the code
getSupportActionBar().hide();
Here is the NPE;
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.hide()' on a null object reference
I made sure all the activity classes extend AppCompatActivity but I still got the same NPE. So then I commented the below fields in the dependency library's theme.
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
This time my app didn't fail with NPE but I see this message in the logcat when the control passes on to the code in the dependency library.
I/AppCompatDelegate: The Activity's LayoutInflater already has a Factory installed so we can not install AppCompat's
i think ,if u set
<item name="windowActionBar">false</item>
u need setSupportActionBar(uToolbar).
if u could't use toolbar,u can try
<item name="windowActionBar">true</item>

Categories

Resources