PreferenceFragmentCompat setting the theme - android

Beginner coder here.
I am using PreferenceFragmentCompat to make a preference fragment that I can use with getSupportFragmentManager().
https://plus.google.com/+AndroidDevelopers/posts/9kZ3SsXdT2T
I am following the directions there, except I'm not sure how to set the preferenceTheme. My app crashes when I click on the settings menu with this exception is thrown
IllegalStateException: Must specify preferenceTheme in theme.
Where do I set the theme?

In values/styles.xml you have to add:
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>

use this:
<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>
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
</style>

Related

you need to use a theme.appcompat

I'm not a developer. I have a problem while editing a google search widget. Google app crashes with this log: https://del.dog/bihagetole
What should i do to fix that?
You must define the theme parent in your styles.xml file
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. This one does not have a action bar for example -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>

ScrimBackground from Theme.MaterialComponents is not Working

I'm trying to change the scrimBackground that show up when you opened a dialog. And I know that in the new MaterialComponents-Theme is an attribute for this case (scrimBackground). But it is currently not working for me.
On the material.io website that background is also descriped as the scrimBackground and it looks like that it is customizable from the Theme. Has anyone an idea what I'm doing wrong?
https://material.io/design/components/dialogs.html#theming
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="scrimBackground">#android:color/holo_blue_light</item>
<item name="dialogTheme">#drawable/window_scrim</item>
<item name="android:dialogTheme">#style/DialogTheme</item>
<item name="alertDialogTheme">#style/AlertDialogTheme</item>
<item name="android:alertDialogTheme">#style/AlertDialogTheme</item>
</style>
<style name="DialogTheme" parent="Theme.MaterialComponents.Dialog">
<item name="scrimBackground">#drawable/window_scrim</item>
</style>
<style name="AlertDialogTheme" parent="Theme.MaterialComponents.Dialog.Alert">
<item name="scrimBackground">#drawable/window_scrim</item>
</style>
The Material code does not appear to use this attribute even though it is defined. This issue tracks this problem. In the meantime, you may be able to change this without a Material Theme using the advise in Changing default Android fade/scrim color when calling a Dialog.

Removing the default toolbar in an activity android

Before upgrading to android 3.1.I usually just change the theme to a theme. app compact. NoTitleBar but the new version of android studio is having errors recognizing it.I solved this problem by adding base to the beginning. But I can seem to find any answer regarding a style theme that supports removing the custom bar.
In your res/values/styles.xml you have this similar block of code.
Ensure that you use Theme.AppCompat.Light.NoActionBar as parent of your theme
<!-- Base application theme. -->
<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>
</style>
Add this style in style file . where other styles are mentioned .
<!-- Base application theme. -->
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimaryDark</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimaryDark</item>
<item name="android:statusBarColor">#color/lightgreycolor</item>
</style>
In my case, i had to change parent theme in res/values/themes.xml

Failed to find style ... in current theme

I've faced a questionable error during my work with android studio.
Everytime I start studio and create a new project there is another render error
Failed to load AppCompat ActionBar with unknown error.
I do not clearly understand what does it mean, but it is easy to deal with it via replacing
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
but evertime I add new element to the layout, there is error
Failed to find style ... in current theme
I have found a solution, that helped almost everybody except me. But changing theme now doesn't solve the problem.
If anybody know how to deal with it please help.
You can copy the style name floatingactionbuttonstyle and included it in your apptheme.
Add this line
<item name="floatingActionButtonStyle">#style/Widget.Design.FloatingActionButton</item>
And finally theme look like this
<!-- Base application theme. -->
<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="floatingActionButtonStyle">#style/Widget.Design.FloatingActionButton</item>
</style>
Just add the style name when error occured in layout editor & add the responding styles.
Here some other few elements am added in styles for others.
<!-- Base application theme. -->
<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="chipStyle">#style/Base.Widget.MaterialComponents.Chip</item>
<item name="chipGroupStyle">#style/Widget.MaterialComponents.ChipGroup</item>
<item name="bottomNavigationStyle">#style/Widget.Design.BottomNavigationView</item>
<item name="coordinatorLayoutStyle">#style/Widget.Support.CoordinatorLayout</item>
<item name="bottomAppBarStyle">#style/Widget.MaterialComponents.BottomAppBar</item>
<item name="floatingActionButtonStyle">#style/Widget.Design.FloatingActionButton</item>
</style>
You can add default style with style name. Then you resolve this error.
In your app gradle under dependencies use this:
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
if you heven't already.

Editing activity theme

I'm trying to edit theme like this:
<style name="MyAppTheme" parent="#android:style/Theme.DeviceDefault.Light.DarkActionBar">
<item name="android:background">#color/colorPrimary</item>
</style>
But this colours my whole activity. Instead I want only action bar to be coloured with my custom color. How to achieve this?
Edit:
I've managed to achieve desired result by using Theme Editor and creating custom theme with it.
Try this
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
and please read this for more info
Use AppCompat theme. Specify colorPrimaryatribute since the ActionBar background color depends on it.
<style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
</style>
Also you can try it like this ,
Use a parent style and declare your whatever Widget style inside the parent one.Here use android:actionBarStyle
See the example below
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
set MyTheme in your activity
Note : ActionBar will not work for your target environment which is at API level 10

Categories

Resources