Updating day/night mode capable Android app to MaterialComponents theme, but getting incorrect theme error when inflating material widgets - android-widget

EDIT: On further inspection, it seems to be that only NightMode causes this crash, regardless of whether or not I am explicitly setting it myself, or letting Android's system wide setting take care of it!
I have an app that supports day/night mode using AppCompat theme. On startup, it applies either the day/night style from a stored setting (the user can update the setting at anytime from within the app as well).
To do so:
int mode = GlobalAppSettings.getStoredSettings().nightModeEnabled() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO;
AppCompatDelegate.setDefaultNightMode(mode);
I recently decided I wanted to use the Chip widget from material to implement tags, but when I the app tries to inflate a view with a Chip in it, I get the error:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
I have updated my themes in my style to be derived from MaterialComponents, but nothing seemed to help. It still crashed. Then I commented out:
AppCompatDelegate.setDefaultNightMode(mode);
And while the app is seemingly stuck in day mode, the Chip is now inflated correctly. Is the AppCompatDelegate method of forcing the day/night theme not compatible with MaterialComponents.DayNight theme?
Has anyone else experienced this issue?
My styles:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowDisablePreview">true</item>
</style>
<style name="SplashTheme" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">#drawable/launch_image</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />
<style name="EditText.Search" parent="Widget.AppCompat.EditText">
<item name="colorControlNormal">#color/black_overlay</item>
<item name="colorControlActivated">#color/black_overlay</item>
</style>
<style name="GameyeToolbarTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/toolbar_title_color</item>
<item name="android:textSize">#dimen/toolbar_title_text_size</item>
</style>

I ended up just setting the theme on the Chip directly with
android:theme="#style/Theme.MaterialComponents"
Which seems like it shouldn't be necessary given that my them derives from MaterialComponents. Maybe it's a bug in material?
I opened up a ticket on material to see if they had any ideas.
https://github.com/material-components/material-components-android/issues/1872

Related

How to change cursor color in html-editor-enhanced flutter

I am using html-editor-enhanced to compose.
I'm having problems synchronizing the cursor colors with the app's colors. when I focus on Editor, the default color of the cusor is green. while my app has a different color. How do I change the color of this cursor?
Hope to get help from the community.
I have found the answer to my question.
In android native. > Res>value> style.xml
add this line
<item name="android:colorControlActivated">#2F93EF</item>
Full code
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
<item name="android:colorControlActivated">#2F93EF</item>
</style>
</resources>

When I swipe from left to right, I don't want it to exit the wearos application in flutter

When I swipe from left to right, I don't want it to exit the wearos application (in flutter/wearos). What can I do for this?
actually, this path writes for kotlin and java in androiddevelopers but l can't see for flutter. so l wrote it for flutter. almost everything is same.
you should open styles.xml(android/app/src/main/res/values/styles.xml).Then you should write false this in Launch theme.
so it should looks like this
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
<item name="android:windowSwipeToDismiss">false</item>
</style>

how to let splash page full screen in flutter

how to let the splash page full screen in flutter?
i got how to set splash page in flutter.dev
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
Inside your Android module go to the app/src/main/res/values
Open up the file name styles.xml
Inside this file you will have a below code that is your custom style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
</resources>
You need add the below line in it:
<item name="android:windowFullscreen">true</item>
Like Below:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
Once you add the above line app stays in fullscreen mode for the entire life-cycle. To disable it you need to define a normal theme to be applied to FlutterActivity after the launch screen is gone and in that theme add the above line with value "false".
Like Below:
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
<item name="android:windowFullscreen">true</item>
</style>
<style name="NormalTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">#drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
Put your image inside the drawable folder and call it in src
<item><bitmap android:gravity="center" android:src="#drawable/splash" /> </item>

How to fix the App name on the top of the Activity

In my design page of My Android Studio Project, the App Name is shown in the top of the activity(Action Bar). But, when I debug the App, the App name is not Shown on the top of the Activity. I want the App name should be shown. How to fix it.
My styles.xml is...
<!-- 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" />
Set your App theme to Theme.AppCompat.Light.DarkActionBar in style.xml
For e.g.
<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>
I think you was asking about ActionBar
from docs
A primary toolbar within the activity that may display the activity
title, application-level navigation affordances, and other interactive
items.
Beginning with Android 3.0 (API level 11), the action bar appears at
the top of an activity's window when the activity uses the system's
Holo theme (or one of its descendant themes), which is the default.
You may otherwise add the action bar by calling
requestFeature(FEATURE_ACTION_BAR) or by declaring it in a custom
theme with the windowActionBar property.
If you want to change it from java code, write in
Activity.java
ActionBar ab = getActionBar();
ab.setTitle("My new title");
Or, in the Androidmanifest.xml file:
<activity
android:name=".MyActivity"
android:icon="#drawable/my_icon"
android:label="My new title" />
hope my answer help you..

Android - Customizing the Spinner widget Look and Feel

Is it possible to change the color of the radio button in the Android spinner widget. By default it displays the green color for the radio button.
I need to change it to some other color, is it possible, and how?
I know this is an old question now, but here goes...
You will need to create a custom Theme and apply it to the Activity with your spinner.
First, you need to create images for the checked/unchecked states of the 'new' radio, you could just pull the given images btn_radio_on.png and btn_radio_off.png from the sdk's res/drawable-* folder(s). Edit them to look how you want (such as changing color or whatever) and save off to your project.
Next, create a new xml file in your res/values folder, and add the following:
<resources>
<style name="CustomSpinnerRadioTheme" parent="#android:style/Theme">
<item name="android:spinnerDropDownItemStyle">#style/EditedRadio</item>
</style>
<style name="EditedRadio" parent="#android:style/Widget.DropDownItem.Spinner">
<item name="android:checkMark">#drawable/edited_radio</item>
</style>
</resources>
Then, create another xml file in res/drawable named edited_radio.xml, and it should contain the following:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="#drawable/btn_radio_off" />
<item android:state_checked="true" android:drawable="#drawable/btn_radio_on" />
</selector>
just be sure to reference your edited images for the checked states. Then you just have to apply the CustomSpinnerRadioTheme to your Activity and run!
A good resource I found is Applying Styles and Themes especially the additional reference on Android Styles (styles.xml) and Android Themes (themes.xml)