The title says it all: how can I style my PreferenceFragmentCompat. My v14/style.xml is
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:editTextStyle">#style/Widget.EditText.White</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
</style>
<style name="Widget.EditText.White" parent="#android:style/Widget.EditText">
<item name="android:textColor">#ffffffff</item>
</style>
</resources>
The base theme has a black background - the preferences screen is then unreadable as I have black text on that black background.
I've tried many things but I cannot change the text colour.
What I've had to do is to set the fragment container background colour to white whilst the settings fragment is active. An ugly hack and not what I want to have to do.
To answer my own question: my v14/style.xml is now
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:editTextStyle">#style/Widget.EditText.White</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="Widget.EditText.White" parent="#android:style/Widget.EditText">
<item name="android:textColor">#ffffffff</item>
</style>
<style name="PreferenceThemeOverlay.v14">
<item name="android:background">#color/settings_background</item>
<item name="android:textColor">#color/settings_text_colour</item>
<item name="android:textColorSecondary">#color/settings_text_colour_secondary</item>
</style>
</resources>
My problem is now to style a ListPreference.
Why is this so hard? If there is any documentation relating to styling preferences, it is well hidden. Grrrrrr!
Take a look at README for github project
Gericop/Android-Support-Preference-V7-Fix
Related
I'm trying to set up my styles to make all buttons a particular color combination, specifically blue with white text. Here's my main styles.xml:
<resources>
<style name="CustomTheme" parent="MaterialDrawerTheme.Light.DarkToolbar">
<!-- various items -->
<item name="android:buttonStyle">#style/ButtonStyle</item>
</style>
<!-- a couple of other styles -->
<style name="ButtonStyle" parent="android:style/Widget.Button">
<item name="android:textSize">19sp</item>
<item name="android:textColor">#color/primaryTextContrast</item>
<item name="android:background">#color/primary</item>
</style>
</resources>
And in the manifest:
<application
android:name=".CustomApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/application_name"
android:theme="#style/CustomTheme">
color/primary is dark blue, and color/primaryTextContrast is white. On Lollipop, the button looks perfect. On a 4.1 device, it's light gray with black text. Every resource I've found for doing this looks exactly like what I'm doing so I don't know what I'm missing here.
I'm having a similar issue with controlling text size in the base style definition as well.
Update: here are the colors.
<resources>
<color name="primary">#3F51B5</color>
<color name="dark">#303F9F</color>
<color name="accent">#FFCA28</color>
<color name="background">#android:color/white</color>
<!-- Color for text displayed on top of the primary or dark color -->
<color name="primaryTextContrast">#android:color/white</color>
<!-- Color for text displayed on the background color (which I think will always be white) -->
<color name="basicText">#color/primary</color>
<!-- Color for text displayed on the accent color -->
<color name="accentText">#303F9F</color>
</resources>
Here's v19/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="FullscreenTheme" parent="MaterialDrawerTheme.Light.DarkToolbar.TranslucentStatus">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
Here's v21:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="CustomTheme">
<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>
</resources>
I don't think either of these is what's making it work properly on 5.1.
Using AppCompat 22.1.+ (22.2.0 should work too), I defined a Style like this:
<style name="MyApp.Button.Red" parent="Base.Widget.AppCompat.Button">
<item name="colorButtonNormal">#color/primary</item>
<item name="android:colorButtonNormal">#color/primary</item>
<item name="android:textColor">#android:color/white</item>
</style>
and then applied the theme in a button using the native theme attribute from android namespace, as said in this awesome post from Chris Banes.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_button"
android:theme="#style/MyApp.Button.Red" />
I tried adding buttonStyle without the android: prefix and it solved the problem. Yeah, weird.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="buttonStyle">#style/ButtonStyle</item>
<item name="android:buttonStyle">#style/ButtonStyle</item>
</style>
gradle:compile 'com.android.support:appcompat-v7:22.2.0'
For theme to work properly in android lollipop, you need to extend
ActionBarActivityinstead of Activity.
By doing this change,your theme setting should work properly.
This is general for other people that for lower version of android,you should not use android: tag in item-name definition
`
Am trying to change the background color of the contextual action bar.
I did it in the following manner
v21/themes.xml & themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionModeOverlay">true</item>
<item name="actionModeStyle">#style/Widget.ActionMode</item>
<item name="android:actionModeStyle">#style/Widget.ActionMode</item>
</style>
</resources>
styles.xml
<style name="Widget.ActionMode" parent="#style/Widget.AppCompat.ActionMode">
<item name="background">#color/highlight_green</item>
</style>
The background color works fine in pre-lollipop devices. But does not work in lollipop.
Note: Tried adding
<item name="android:actionModeBackground">#color/highlight_green</item>
<item name="actionModeBackground">#color/highlight_green</item>
as well. But did not work.
Had the same problem since last library update, and adding the "actionModeBackground" item in my theme solved it.
Are you sure you are adding it under MyTheme, and not under Widget.ActionMode ?
Try only the next code:
Styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionModeStyle">#style/ActionMode</item>
</style>
<style name="ActionMode" parent="Widget.AppCompat.ActionMode">
<item name="background">#color/color_bar</item>
<item name="backgroundSplit">#color/color_bar</item>
</style>
I am currently trying tu build my own DialogFragment theme.
One of my requirement is to use an icon at the right of the title.
First idea
Simply using:
this.getDialog().getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.dialog_title);
But unfortunately, this line of code has no result.
Second idea
Provinding my own layout -this.setContentView()- with this textview:
<TextView
android:id="#+id/tvTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="From XML"
android:textAppearance="#android:style/TextAppearance.DialogWindowTitle" />
This works, because I can read the text, but it still written in default black font.
I was expecting TextAppearance.DialogWindowTitle to give my text a title appareance (blue in Holo with big font size)
Any idea or suggestion?
EDIT
This nearly did the trick:
<style name="Dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
<style name="MyOwnDialogTitle">
<item name="android:drawableRight">#drawable/MyRightImage</item>
</style>
but android:drawableRight just broke the title layout:
SECOND EDIT
This is a little bit better:
<style name="Dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
<style name="MyOwnDialogTitle">
<item name="android:textAppearance">#android:style/TextAppearance.DialogWindowTitle</item>
<item name="android:drawableRight">#drawable/icon</item>
</style>
Maybe you can extend the default style in this manner:
res/values/dialogstyles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
<style name="MyOwnDialogTitle">
<item name="android:drawableRight">#drawable/MyRightImage</item>
</style>
</resources>
res/values-v11/dialogstyles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Dialog" parent="#android:style/Theme.Holo.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
</resources>
And override your DialogFragment's onCreate:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog);
}
Working Example
I am searching for your first requirement. but for second requirement, why dont you try with changing the color to style of the TextAppearance.DialogWindowTitle with your custom style ?
I have just check the android resources where there is style like below:
<style name="DialogWindowTitle">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">#style/TextAppearance.DialogWindowTitle</item>
</style>
and for TextAppearance.DialogWindowTitle style:
<style name="TextAppearance.DialogWindowTitle">
<item name="android:textSize">18sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">?textColorPrimary</item>
</style>
Now, you can change the color of your TextAppearance.DialogWindowTitle style and do as you want.
Hope you got the point.
Feel free to comment.
Have you tried to use #android:style/Theme.Holo.Light.Dialog as your parent in styles? This will work only in Android 3+ because in earlier version there is no theme Holo, but you can create your own to look like it for lower versions of Android.
I wish to have a transluscent background for an activity, so that the previous activity can be seen beneath this activity. Something like a transluscent menu that pops up over a videa being played in the background.
Is this possible? Can you tell me how?
Note:I cannot use the default transluscent theme from android, since I am using my own customised background and theme for my application.
Pls help. Below is my style.xml wherein my_btn and my_list are selectors :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="btnstyle" parent="#android:style/Widget.Button">
<item name="android:textColor">#FFFFFF</item>
<item name="android:background">#drawable/my_btn</item>
</style>
<style name="liststyle" parent="#android:style/Widget.ListView">
<item name="android:listSelector">#drawable/my_list</item>
</style>
<style name="theme" parent="android:Theme.Translucent">
<item name="android:windowBackground">#drawable/background</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:buttonStyle">#style/btnstyle</item>
<item name="android:listViewStyle">#style/liststyle</item>
</style>
</resources>
Apply Translucent theme to your activity in AndroidManifest.xml
<activity android:theme="#android:style/Theme.Translucent">
I have a class, TextViewStyled, which extends TextView
In my theme XML, how do I apply a style to all my TextViewStyled widgets on Activities with a chosen theme?
I have this simple theme, but I want to limit the Black Gold style to TextViewStyled Widgets without specifying the Black Gold in the TextViewStyled style attribute. This is one of many themes which will be switched dynamically.:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyThemeOneofMany" parent="android:Theme.NoTitleBar.Fullscreen">
<item name="android:???????????">#style/TextViewStyled_Black_Gold</item>
</style>
<style name="TextViewStyled_Black_Gold" parent="#android:style/Widget.TextView">
<item name="android:background">#1E1921</item>
<item name="android:textColor">#A85E4F</item>
<item name="android:textColorLink">#FFBC4F</item>
<item name="android:textStyle">normal</item>
</style>
</resources>
For AppCompat theme (2.3.3+):
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:textViewStyle">#style/PizzaSizeWidget</item>
</style>
<style name="CustomTextView" parent="#android:style/TextAppearance.Widget.TextView">
<item name="android:background">#1E1921</item>
<item name="android:textColor">#A85E4F</item>
<item name="android:textStyle">normal</item>
<item name="android:textSize">93sp</item>
</style>
In order to set the style for TextViews in your custom Theme use the name "android:textViewStyle":
<style name="MyThemeOneofMany" parent="android:Theme.NoTitleBar.Fullscreen">
<item name="android:textViewStyle">#style/TextViewStyled_Black_Gold</item>
</style>
Found it when looking through the official android themes.xml [click].
I found that updating the styles works when overriding the base textview class after the inflation event.