I simply added a spinner with the Toolbar and working fine in all devices of Android up to Android version 5. However when I tested this thing with recently launched Android 6 it's not displaying items in spinner, just blank white background.
What changes I need to make out to resolve this abrupt behaviour. Here below is styles used for this spinner in Toolbar.
style v21 :--
<style name="Widget.MyApp.Toolbar.Spinner" parent="Widget.MyApp.HeaderBar.Spinner">
<item name="android:dropDownSelector">?android:selectableItemBackground</item>
<item name="android:divider">#null</item>
<item name="android:overlapAnchor">true</item>
<item name="android:gravity">left</item>
<item name="android:background">#drawable/toolbar_language_bg</item>
<item name="android:popupBackground">#color/text_color_white</item>
</style>
style:-
<style name="Widget.MyApp.Toolbar.Spinner" parent="Widget.MyApp.HeaderBar.Spinner">
<item name="android:dropDownSelector">?android:selectableItemBackground</item>
<item name="android:divider">#null</item>
<item name="android:gravity">left</item>
<item name="android:background">#drawable/toolbar_language_bg</item>
<item name="android:popupBackground">#color/text_color_white</item>
</style>
Related
Please tell me, I have an application that uses a webView in full screen. As of android 10, the navigation bar started to overlap my webView:
By putting <item name="android:windowTranslucentNavigation">true</item>, the navigation bar stopped overlapping the webView, but I would like to make it black and but not transparent. How can I implement this? Perhaps I can do something differently so that the navigation bar does not overlap the webView? I'm new to this.
My style.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/background_splashscreen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:navigationBarColor">#color/black</item>
</style>
Thanks in advance.
So in the app I am making, I have both a dark and light theme. The light theme works fine, but the alert dialogs I have still show the background the same as the light theme. Since it is dark, the text changes to light and the user can't see anything. Is there a certain attribute I need to change?
Here is the styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#E53935</item>
<item name="colorPrimaryDark">#C62828</item>
<item name="android:navigationBarColor">#E53935</item>
<item name="android:colorAccent">#1565C0</item>
<item name="android:colorForeground">#color/foreground_material_light</item>
<item name="android:colorBackground">#color/background_material_light</item>
<!-- Other attributes -->
</style>
<style name="Dark" parent="#style/AppTheme" >
<item name="android:colorForeground">#color/foreground_material_dark</item>
<item name="android:colorPrimary">#color/primary_material_dark</item>
<item name="android:colorPrimaryDark">#color/primary_dark_material_dark</item>
<item name="android:colorAccent">#color/accent_material_dark</item>
<item name="android:navigationBarColor">#color/primary_material_dark</item>
<item name="android:colorBackground">#color/background_material_dark</item>
<item name="android:textColorPrimary">#android:color/primary_text_dark</item>
<item name="android:textColorPrimaryInverse">#android:color/primary_text_light</item>
<item name="android:textColorSecondary">#android:color/secondary_text_dark</item>
<item name="android:textColorSecondaryInverse">#android:color/secondary_text_light</item>
<item name="android:textColorTertiary">#android:color/tertiary_text_dark</item>
</style>
Here is what it shows up as:
Solved: You need to create your own xml like this:
<item name="alertDialogTheme">#style/DarkAlertDialog</item>
With this being your custom dialog:
<style name="DarkAlertDialog" parent="Theme.AppCompat.Dialog">
<item name="background">#color/background_material_dark</item>
</style>
Use the parent AppCompat and then use colorPrimary and colorAccent properties (without an Android prefix) to theme things.
Right now the styles are coming from a dialog subtheme and not being affected by these style definitions.
This question already has answers here:
Disable activity slide-in animation when launching new activity?
(11 answers)
Closed 7 years ago.
Is there any way to change / disable that animation when an app is opening (e.g. slide up animation in Lolipop).
I have tried this, but without success:
<item name="android:windowEnterAnimation">#null</item>
<item name="android:windowExitAnimation">#null</item>
<item name="android:windowAnimationStyle">#null</item>
You can create your custom animation. Using basics of themes in android it can be done. Below just delete any line you don't want to define your own animation for and it will fall back to the default android animation.
<!-- this goes in your theme -->
<item name="android:windowAnimationStyle">#style/MyActivityAnimations</item>
<!-- Standard animations for a full-screen window or activity. -->
<style name="MyActivityAnimations" parent="#android:style/Animation.Activity">
<item name="activityOpenEnterAnimation">#anim/activity_open_enter</item>
<item name="activityOpenExitAnimation">#anim/activity_open_exit</item>
<item name="activityCloseEnterAnimation">#anim/activity_close_enter</item>
<item name="activityCloseExitAnimation">#anim/activity_close_exit</item>
<item name="taskOpenEnterAnimation">#anim/task_open_enter</item>
<item name="taskOpenExitAnimation">#anim/task_open_exit</item>
<item name="taskCloseEnterAnimation">#anim/task_close_enter</item>
<item name="taskCloseExitAnimation">#anim/task_close_exit</item>
<item name="taskToFrontEnterAnimation">#anim/task_open_enter</item>
<item name="taskToFrontExitAnimation">#anim/task_open_exit</item>
<item name="taskToBackEnterAnimation">#anim/task_close_enter</item>
<item name="taskToBackExitAnimation">#anim/task_close_exit</item>
<item name="wallpaperOpenEnterAnimation">#anim/wallpaper_open_enter</item>
<item name="wallpaperOpenExitAnimation">#anim/wallpaper_open_exit</item>
<item name="wallpaperCloseEnterAnimation">#anim/wallpaper_close_enter</item>
<item name="wallpaperCloseExitAnimation">#anim/wallpaper_close_exit</item>
<item name="wallpaperIntraOpenEnterAnimation">#anim/wallpaper_intra_open_enter</item>
<item name="wallpaperIntraOpenExitAnimation">#anim/wallpaper_intra_open_exit</item>
<item name="wallpaperIntraCloseEnterAnimation">#anim/wallpaper_intra_close_enter</item>
<item name="wallpaperIntraCloseExitAnimation">#anim/wallpaper_intra_close_exit</item>
</style>
In my app in setings I use EditTextPreference , and on android API uder 11 edittext field has black background and black text color.
How can I chenge EditTextPreferences background color ?
I tried:
in theme :
<item name="android:editTextPreferenceStyle">#style/EditTextAppTheme</item>
in style:
<style name="EditTextAppTheme" parent="android:Widget.EditText">
<item name="android:background">#drawable/edit_text_holo_light</item>
<item name="android:textColor">#000000</item>
</style>
If I set style to :
<style name="EditTextPreferences" parent="android:Preference.DeviceDefault.DialogPreference.EditTextPreference">
<item name="android:background">#drawable/edit_text_holo_light</item>
<item name="android:textColor">#FF0000</item>
</style>
And theme to :
<item name="android:editTextPreferenceStyle">#style/EditTextPreferences</item>
I got error:
error: Error retrieving parent for item: No resource found that matches the given name 'android:Preference.DeviceDefault.DialogPreference.EditTextPreference'.
I have been trying to figure this out as well for the past couple of days. I've found that all the EditTextPrefence extends is AlertDialog and EditText. So if you can style both of those in your theme, you will find the result you are looking for in a EditTextPreference. Here's what I'm working with:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="LightTheme" parent="android:Theme.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:background">#color/greyscale2</item>
<item name="android:textColor">#color/greyscale16</item>
<item name="android:textViewStyle">#style/LightTextView</item>
<item name="android:buttonStyle">#style/LightButton</item>
<item name="android:editTextStyle">#style/LightEditText</item>
<item name="android:alertDialogTheme">#style/LightDialog</item>
<item name="android:dialogPreferenceStyle">#style/LightDialog</item>
<item name="android:colorBackground">#color/greyscale2</item>
<item name="android:colorBackgroundCacheHint">#color/greyscale1</item>
</style>
<!-- TextView -->
<style name="LightTextView" parent="android:Widget.TextView">
<item name="android:textColor">#color/greyscale16</item>
<item name="android:background">#android:color/transparent</item>
</style>
<!-- Button -->
<style name="LightButton" parent="android:Widget.Button">
<item name="android:textColor">#color/greyscale16</item>
<item name="android:background">#drawable/light_button_background</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
</style>
<style name="LightCheckBox" parent="android:Widget.CompoundButton.CheckBox">
<item name="android:background">#color/greyscale2</item>
</style>
<style name="LightEditText" parent="android:style/Widget.EditText">
<item name="android:background">#color/greyscale1</item>
<item name="android:editTextBackground">#color/greyscale2</item>
<item name="android:textColor">#color/greyscale16</item>
<item name="android:button">#style/DarkButton</item>
<item name="android:inputType">number</item>
</style>
<style name="LightDialog" parent="#android:style/Theme.Dialog">
<item name="android:background">#color/greyscale2</item>
<item name="android:textColor">#color/greyscale16</item>
<item name="android:textViewStyle">#style/LightTextView</item>
<item name="android:buttonStyle">#style/LightButton</item>
<item name="android:divider">#color/greyscale14</item>
</style>
Notice the
<item name="android:dialogPreferenceStyle">#style/LightDialog</item> attribute in my base theme. I found the styleable resource here, more specifically alertDiaolg here (Note: These can also be found in your SDK directory on your computer)
I hope this at least heads you in the right direction, I have been struggling to figure this out (my first theme in my apps). Happy Coding!
I think the effect you've observed is a bug in the Gingerbread emulator.
After changing the activity's theme and restarting the emulator the EditTextPreference appeared as above.
First extend EditTextPreference and override onPrepareDialogBuilder, inverting background color for versions below Honeycomb:
public class CustomEditTextPreference extends EditTextPreference {
/**
* Prepares the dialog builder to be shown when the preference is clicked.
* Use this to set custom properties on the dialog.
* <p>
* Do not {#link AlertDialog.Builder#create()} or
* {#link AlertDialog.Builder#show()}.
*/
#Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);
}
}
Then replace in your preferences.xml all
<EditTextPreference ... />
with
<your.package.CustomEditTextPreference ... />
I had this exact issue when I switched to the API v21 AppCompat (I think - it previously used to work just fine at least).
My solution was to define the style for android:editTextStyle explicitly in my theme - here is my complete styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<item name="android:editTextStyle">#android:style/Widget.EditText</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
The result is an editText that looks the same as in #Jesse Webb's screenshot.
How can i apply a custom ActiobbarSherlock to my activities. I am looking for something like this this. I know the four square application uses the SherlockActionBar how can i do this?
This is my current style ...
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#449def</item>
<item name="background">#0099CC</item>
<item name="android:titleTextStyle">#style/Theme.ActionBar.TitleTextStyle</item>
<item name="icon">#drawable/ic_launcher</item>
<item name="backgroundSplit">#drawable/gray_seprator</item>
<item name="android:displayOptions">showTitle|homeAsUp</item>
<item name="displayOptions">showTitle|homeAsUp</item>
</style>
Kind Regards