I am using support preference library and every PreferenceCategory fill the whole screen with blank space and then show the preferences that it contains. I have tried changing PreferenceCategory style attribute - layout_height to wrap_content and it didn't work.
My preference styles:
<style name="PreferenceThemeOverlay">
<item name="preferenceScreenStyle">#style/Preference.PreferenceScreen</item>
<item name="preferenceFragmentStyle">#style/PreferenceFragment</item>
<item name="preferenceCategoryStyle">#style/Preference.Category</item>
<item name="preferenceStyle">#style/Preference</item>
<item name="preferenceInformationStyle">#style/Preference.Information</item>
<item name="checkBoxPreferenceStyle">#style/Preference.CheckBoxPreference</item>
<item name="switchPreferenceCompatStyle">#style/Preference.SwitchPreferenceCompat</item>
<item name="dialogPreferenceStyle">#style/Preference.DialogPreference</item>
<item name="editTextPreferenceStyle">#style/Preference.DialogPreference.EditTextPreference</item>
<item name="preferenceFragmentListStyle">#style/PreferenceFragmentList</item>
<item name="android:subtitleTextStyle">#color/dark_gray</item>
</style>
My prefernce xml:
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<android.support.v7.preference.PreferenceCategory
android:key="pref_user_settings"
android:title="#string/pref_group_user">
<android.support.v7.preference.ListPreference
android:defaultValue="Publisher"
android:entries="#array/pref_user_types"
android:entryValues="#array/pref_user_types"
android:key="pref_user_type"
android:title="#string/pref_title_user_type" />
</android.support.v7.preference.PreferenceCategory>
This is how it looks:
The way i solved it out is customing the preference category file.
Solution:
Create a new layout xml file called custom_preference_category:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/gray"
android:paddingTop="8dp"
android:id="#android:id/title" />
Then add this to your styles file:
<style name="Preference.Category">
<item name="android:layout">#layout/custom_preference_category</item>
<item name="android:shouldDisableView">false</item>
<item name="android:selectable">false</item>
</style>
<style name="PreferenceThemeOverlay">
<item name="preferenceScreenStyle">#style/Preference.PreferenceScreen</item>
<item name="preferenceFragmentStyle">#style/PreferenceFragment</item>
<item name="preferenceCategoryStyle">#style/Preference.Category</item>
<item name="preferenceStyle">#style/Preference</item>
<item name="preferenceInformationStyle">#style/Preference.Information</item>
<item name="checkBoxPreferenceStyle">#style/Preference.CheckBoxPreference</item>
<item name="switchPreferenceCompatStyle">#style/Preference.SwitchPreferenceCompat</item>
<item name="dialogPreferenceStyle">#style/Preference.DialogPreference</item>
<item name="editTextPreferenceStyle">#style/Preference.DialogPreference.EditTextPreference
</item>
<item name="preferenceFragmentListStyle">#style/PreferenceFragmentList</item>
</style>
And then use this style in your main app theme:
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
I did it a lot of time ago so I'm not sure if this all I've done, so give me a feedback if something is missing.
Related
I'm trying to change the colour of the selected icon in the bottom navigation bar. I already have a selector, that changes the colour of the selected icon. My problem is, that if the App theme changes, the colours won't change.
How can I change the selector colour, based on the App theme?
This is the selector I already have:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/standardThemeAccentSelected" android:state_checked="true" />
<item android:color="#color/standardThemeAccentNonSelected" />
</selector>
Those are my themes/styles:
<resources>
<!-- Base application theme. -->
<style name="baseTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/standardThemePrimaryColor</item>
<item name="colorPrimaryDark">#color/standardThemePrimaryDark</item>
<item name="android:textColor">#color/standardThemeAccentText</item>
<item name="android:windowBackground">#color/standardThemeAccentBackground</item>
<item name="itemIconTint">#color/standardThemeAccentNonSelected</item>
<item name="itemTextColor">#color/standardThemeAccentNonSelected</item>
<item name="colorAccent">#color/standardThemeAccentContent</item>
<item name="drawableTint">#color/standardThemeAccentText</item>
<item name="bottomNavigationStyle">#style/baseThemeNav</item>
<!--Navigation-->
<item name="android:navigationBarColor">#color/standardThemePrimaryColor</item>
</style>
<!--Base Theme Nav-->
<style name="baseThemeNav" parent="Widget.Design.BottomNavigationView">
<item name="android:background">#color/standardThemePrimaryColor</item>
</style>
<!--Black Theme-->
<style name="blackTheme" parent="Theme.AppCompat">
<item name="colorPrimary">#color/blackThemePrimaryColor</item>
<item name="colorPrimaryDark">#color/blackThemePrimaryDark</item>
<item name="android:textColor">#color/blackThemeAccentText</item>
<item name="android:windowBackground">#color/blackThemeAccentBackground</item>
<item name="itemIconTint">#color/blackThemeAccentNonSelected</item>
<item name="itemTextColor">#color/blackThemeAccentNonSelected</item>
<item name="colorAccent">#color/blackThemeAccentContent</item>
<item name="drawableTint">#color/blackThemeAccentNonSelected</item>
<item name="bottomNavigationStyle">#style/blackThemeNav</item>
<!--Navigation Style-->
<item name="android:navigationBarColor">#color/blackThemePrimaryColor</item>
</style>
<!--Black Theme nav-->
<style name="blackThemeNav" parent="Widget.Design.BottomNavigationView">
<item name="android:background">#color/blackThemePrimaryColor</item>
</style>
</resources>
I want to change Material TextInputEditText's bubble and cursor color. I tried colorAccent, android:textCursorDrawable these are not working correctly.
Files in here
The material attribute color colorControlActivated do the magic. You have to create a style for your TextInputLayout.
e.g:
<style name="TextInputLayoutAppearance" parent="Widget.Design.TextInputLayout">
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/red</item>
<item name="colorControlHighlight">#color/blue</item>
</style>
Then you have to apply this style in the theme attribute of control:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/lblObservaciones"
android:theme="#style/TextInputLayoutAppearance"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxStrokeColor="#color/blue"
app:hintTextAppearance="#style/TextAppearance.AppCompat.Medium"
app:hintTextColor="#color/blue">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/comments"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="top"
android:inputType="textMultiLine"
android:maxLength="200" />
</com.google.android.material.textfield.TextInputLayout>
Just apply colorControlActivated in app theme(day/night) and all Material TextInputEditField will have the changed cursor color
<item name="android:colorControlActivated">#color/green</item>
You have to use following attributes:
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<item name="colorPrimary">#212121</item>
<item name="colorPrimaryVariant">#000000</item>
<item name="colorOnPrimary">#FFFFFF</item>
<item name="colorSecondary">#2962FF</item>
<item name="colorSecondaryVariant">#0039CB</item>
<item name="colorOnSecondary">#FFFFFF</item>
<item name="colorError">#F44336</item>
<item name="colorOnError">#FFFFFF</item>
<item name="colorSurface">#FFFFFF</item>
<item name="colorOnSurface">#212121</item>
<item name="android:colorBackground">#color/background</item>
<item name="colorOnBackground">#212121</item>
</style>
<color name="background">#FAFAFA</color>
To know more about : Setting up a Material Components theme for Android
I have a simple Button style, like
<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">#color/colorPrimary</item>
<item name="android:textColor">#color/white</item>
</style>
at this point the output is as this
it seems that the style is not applied and the colors are not set correctly. When I change the style to something like this
<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
<item name="android:background">#color/colorPrimary</item>
<item name="android:textColor">#color/white</item>
</style>
I get something like this
Thw Button looks insane, but the style is applied.
How can I retain the Button shape as shiwn in the first picture and apply my styles correctly?
Ok I've found a way to get the Job done quite promisingly
style.xml
<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
<item name="android:background">#drawable/btn_ripple</item>
<item name="android:textColor">#color/white</item>
<item name="android:padding">10dp</item>
<item name="android:minWidth">88dp</item>
<item name="android:minHeight">36dp</item>
<item name="android:layout_margin">3dp</item>
<item name="android:elevation">1dp</item>
<item name="android:translationZ">1dp</item>
</style>
and last the btn_ripple.xml is
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/btn_press">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp" />
<solid android:color="#color/colorPrimary" />
</shape>
</item>
</ripple>
and the result is
Regards
I think the problem may be located in the parent.
<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
I belive the second snippet sets the button style, overriding the parent. Try to remove the parent, and see what happens.
<style name="AppTheme.Button">
<item name="android:background">#color/colorPrimary</item>
<item name="android:textColor">#color/white</item>
</style>
My menu layout looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_change_pin"
android:title="#string/action_change_pin"
android:textColor="#000000"
android:orderInCategory="100"
app:showAsAction="never" />
<item android:id="#+id/action_logout"
android:title="#string/action_logout"
android:orderInCategory="100"
app:showAsAction="never" />
I want to change these two items' text color to white from black. How can i do that?
I think u need to change the style:
try this :
put this in your theme
<item name="android:itemTextAppearance">#style/myCustomMenuTextApearance</item>
and in your styles.xml:
<style name="myCustomMenuTextApearance" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#color/your_color</item>
</style>
should help u out
In your theme.xml
<style name="LightTheme" parent="#style/Theme.AppCompat.Light">
<item name="actionMenuTextColor">#FFF</item>
<item name="android:actionMenuTextColor">#FFF</item>
</style>
Try this:
<style name="ThemeName" parent="#style/Theme.Sherlock.Light">
<item name="actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextColor">#color/white</item>
</style>
I've tried many things to change the text color when i click the "three dot" menu button but it always reverts back to the toolbar (android:theme) theme and not the android:popupTheme. I want the text to be black but it always shows up white.
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/accentColor</item>
</style>
<style name="MaterialWorkout_theme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:textColorSecondary">#48FFFFFF</item>
</style>
<style name="Popup_theme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#000000</item>
<item name="android:textColorSecondary">#38000000</item>
</style>
app_bar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/primaryColor"
android:id="#+id/app_bar"
android:theme="#style/MaterialWorkout_theme"
android:popupTheme="#style/Popup_theme"
>
Here is what it looks like:
http://imgur.com/svRuuHK
Solved it. changed my toolbar.xml file to this:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/primaryColor"
android:id="#+id/tool_bar"
android:theme="#style/MaterialWorkout_theme"
app:popupTheme="#style/Popup_theme">
notice the implementation of:
xmlns:app="http://schemas.android.com/apk/res-auto"
and
app:popupTheme="#style/Popup_theme"
these two lines solved my problem!
You need to define your popup menu theme in your style, not you Toolbar.
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/accentColor</item>
<item name="popupMenuStyle">#style/Popup_theme</item>
</style>
Use below code .I hope this will solve your problem.You can change both background color and textcolor.
<style name="AppFullScreenThemeNight" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<!-- if using android.support.v7.widget.PopupMenu -->
<item name="popupMenuStyle">#style/PopupMenu</item>
<item name="android:itemTextAppearance">#style/TextAppearance</item>
</style>
<style name="PopupMenu" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:popupBackground">#color/button_color</item>
</style>
<style name="TextAppearance">
<item name="android:textColor">#android:color/holo_red_dark</item>
</style>