EDIT: MIUI force Dark Mode to be activated in my app, so the app looks awful.
In some Part of my app when I set Color to "white", it will be shown as White.
If I set it as "gray", it will be shown as Gray.
If I set it as "red", it will be shown as Red.
but: If I set it as "black", it will be "WHITE!"
How can I solve this problem??
Solution is Found!
Setting false to the <item name="android:forceDarkAllowed">true</item>
in App_Resources/Android/src/main/res/values/styles.xml
Thanks to this link:
https://medium.com/#kivind/nativescript-disabling-dark-mode-382e5dfd11bd
so style.xml should looks like:
<style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
<item name="toolbarStyle">#style/NativeScriptToolbarStyle</item>
<item name="android:forceDarkAllowed">false</item>
<item name="colorPrimary">#color/ns_primary</item>
<item name="colorPrimaryDark">#color/ns_primaryDark</item>
<item name="colorAccent">#color/ns_accent</item>
</style>
Meshing up many different solutions, I figured out this walktrough
AppEntryPoint.kt
class AppEntryPoint : Application() {
override fun onCreate() {
super.onCreate()
/*in some XIAOMI devices seems to be necessary*/
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
}
AndroidManifest.xml
<application
android:name=".AppEntryPoint"
...
android:theme="#style/Theme.MyMainTheme">
...
</application>
themes.xml
<style name="Theme.MyMainTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
...
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
I don't know if it is the correct solution, but now it works for me.
There's maybe a strange way to manage this kind of behaviour in some Xiaomi devices...
Hope this answer could be useful also to others
On xiaomi redmi 9 at least had got to set this value false on both night and day themes.xml files. and work like a charm.
Related
I want to change the color of the selected area in the bottom navigation view material 3, but the color does not change in any way. I've tried selector, background, background Tint, and styles. All unsuccessfully.
Currently like this.
It should be like this.
You can change indicator color by overridng it's default style.
Default itemIndicatorStyle :
<style name="Widget.Material3.BottomNavigationView.ActiveIndicator" parent="">
<item name="android:width">#dimen/m3_bottom_nav_item_active_indicator_width</item>
<item name="android:height">#dimen/m3_bottom_nav_item_active_indicator_height</item>
<item name="marginHorizontal">#dimen/m3_bottom_nav_item_active_indicator_margin_horizontal</item>
<item name="shapeAppearance">#style/ShapeAppearance.Material3.NavigationBarView.ActiveIndicator</item>
<item name="android:color">?attr/colorSecondaryContainer</item>
just override the style according to your preference :
<style name="App.Custom.Indicator" parent="Widget.Material3.BottomNavigationView.ActiveIndicator">
<item name="android:color">#color/blue</item>
</style>
And then add this line to your bottomNavigationView xml code :
app:itemActiveIndicatorStyle="#style/App.Custom.Indicator"
you can use this function for change indicator color:
findViewById<BottomNavigationView>(R.id.bottomNavigationView) .itemActiveIndicatorColor = getColorStateList(R.color.white)
and set this annotatin for your onCreate function #RequiresApi(Build.VERSION_CODES.M)
look in the screenshot
I'm struggling to set the right style for my button in the project. I don't know why shapeAppearance not working. Even if I use only cornerSize it's not working.
I have a base style for a button:
<style name="SnButton" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="shapeAppearance">#style/MyShapeAppearance</item>
<item name="backgroundTint">#null</item>
</style>
This is my shape appearance for a button:
<style name="MyShapeAppearance" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">2dp</item>
</style>
This is my base theme: Theme.MaterialComponents.Light.NoActionBar.Bridge
What should I do to force shapeAppearance work in my case? Or at least cornerSize?
I figured out why style was not working!
The problem was in the way I set the color for the button. I've used android:background, but backgroundTint must be used.
I need to change the background color of my entire tab layout dynamically through code in my app. I just need to know the correct line to type. I don't need to change the selected tab or anything. I want to leave the style and text colors and the indicator line as is. I just want to change the background of the entire tab layout dynamically in code. Thank you for your help.
I have already tried the below line of code. Didn't work. Also included my TabLayout XML.
private TabLayout mTabLayout;
mTabLayout = (TabLayout) findViewById(R.id.tabs);
mTabLayout.setBackgroundColor
(this.getResources().getColor(R.color.dark_grey));
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
style="#style/CategoryTab"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_generic_margin_28"
app:tabBackground="#color/app_bar"/>
Thank you for your help.
I solved it by checking the boolean that I have set for night theme prior to setting the content view in onCreate.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences nightModeSwitchState = getSharedPreferences("NightModeSwitchState", 0);
mNightModeSwitchState = nightModeSwitchState.getBoolean("NightModeSwitchState", false);
if (mNightModeSwitchState) {
setContentView(R.layout.activity_book_night);
} else {
setContentView(R.layout.activity_book);
}
I have two layouts made both include tabLayouts. One of them references a style file for tabLayout set to night mode colors with the dark background and the layout references a style file set to regular colors for the tablayout.
<style name="CategoryTab" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#android:color/white</item>
<item name="tabSelectedTextColor">#android:color/white</item>
<item name="tabTextAppearance">#style/CategoryTabTextAppearance</item>
<item name="tabBackground">#drawable/tab_regular_theme</item>
<item name="android:textColorSecondary">#android:color/white</item>
</style>
<style name="CategoryTabNight" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#android:color/white</item>
<item name="tabSelectedTextColor">#android:color/white</item>
<item name="tabTextAppearance">#style/CategoryTabTextAppearance</item>
<item name="tabBackground">#drawable/tab_layout_dark_mode</item>
<item name="android:textColorSecondary">#android:color/white</item>
</style>
The style files reference different drawables that control the background colors as you can see above.. and here are the drawables...
Here is night mode drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/dark_grey" android:state_selected="true"/>
<item android:drawable="#color/dark_grey"/>
</selector>
Here is regular mode drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/app_bar" android:state_selected="true"/>
<item android:drawable="#color/app_bar"/>
</selector>
Everything else is the layouts are identical as not to mess anything up just the style files for the tablayouts are changed. I hope this makes sense. I tested it and it works for me. I have tried so many other things and nothing worked. It is important to call Shared Preference to get the value before checking the boolean. I hope this helps someone.
Does anyone know how can I change this green color that appears in my editText ?
I would like to do it from the layout XML if it is possible
just below the editText image.
Any help is appreciated.
I could resolve it adding: android:backgroundTint="#color/color_you_wat" to the EditText in the layout file
Programmatically:
editText.getBackground().mutate().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_ATOP);
Using theme:
<style name="AppThem" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- change values below to make same eefect for all EditTexts ->
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#color/accent</item>
<item name="colorControlHighlight">#color/accent</item>
</style>
<!-- also you can create different styles with values above for many different views ->
Edit:
You can always use in xml file:
"app:backgroundTint="#color/myColor" in xml.
Don't use android:. Otherwise you would lose backward compability with Android 4.4 and older.
Hope it help
I'll describe my problem first. I'm trying an android app. Doing it using Xamarin Android. I've done the parts I need, the necessary code; but Compiling my code gives me some errors in the Styles.xml file.
The error is like this::
Error APT0000: Error retrieving parent for item: No resource found that matches the given name 'Widget'. (APT0000) (TestALLApp)
Basically 5 errors, the above error repeating itself 5 times for the 5 style definitions in the Stylex xml file.
This is my Styles.xml file::
<resources>
<style name="Widget.SampleContentContainer"> <---- error shown here
<item name="android:paddingTop">#dimen/vertical_page_margin</item>
<item name="android:paddingBottom">#dimen/vertical_page_margin</item>
<item name="android:paddingLeft">#dimen/horizontal_page_margin</item>
<item name="android:paddingRight">#dimen/horizontal_page_margin</item>
</style>
<style name="Widget.SampleDashboard.Grid" parent="Widget">
<item name="android:stretchMode">columnWidth</item>
<item name="android:columnWidth">200dp</item>
<item name="android:numColumns">auto_fit</item>
<item name="android:drawSelectorOnTop">true</item>
<item name="android:horizontalSpacing">#dimen/margin_medium</item>
<item name="android:verticalSpacing">#dimen/margin_medium</item>
</style>
<style name="Widget.SampleDashboard.Item" parent="Widget">
<item name="android:background">#drawable/sample_dashboard_item_background</item>
<item name="android:paddingTop">#dimen/margin_small</item>
<item name="android:paddingLeft">#dimen/margin_medium</item>
<item name="android:paddingRight">#dimen/margin_medium</item>
<item name="android:paddingBottom">#dimen/margin_medium</item>
</style>
<style name="Widget.SampleDashboard.Item.Title" parent="Widget">
<item name="android:layout_marginBottom">#dimen/margin_tiny</item>
<item name="android:textAppearance">?android:textAppearanceLarge</item>
<item name="android:textColor">#09c</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">24sp</item>
</style>
<style name="Widget.SampleDashboard.Item.Description" parent="Widget">
<item name="android:textAppearance">?android:textAppearanceSmall</item>
<item name="android:fontFamily">sans-serif-light</item>
</style>
You can see the line on which the error is shown. Among the references I added to my project were
Xamarin.Android.Support.v4
Xamarin.Android.Support.v7.RecyclerView
That's All. As per the error message I suppose, 'Error retrieving parent for item' should mean it cannot find/locate a parent called 'Widget'. I did search for any nuget package like Xamarin Widget, anything of that name or similar name doesn't exist. At least my nuget package search cannot list/find anything like that. Or is it something to do with a style element definition called 'Widget' too in that xml file? So what is the actual correct thing to be done please, if someone could show me, it'd help me very much. Is it just a missing nuget package? If so what is the proper correct name of it please['widget'].
Please help me a little on this matter.
Thanks so much.
As I have used it before, the parent attribute's value is the parent style that you will start with, then override the various properties within there. For me, I have always used parent attribute values such as "#android:style/Theme.Holo.Light", .Dark, and so on. Unless there is a theme named Widget, I don't see this working.
PS. Obviously, the holo styles were first introduced in android 3.x/4.x, so I doubt that they would work in previous versions of android without including some other stuff to make them work. You used the Xamarin.Forms tag for the question, so this won't be a big deal since XF only runs on android 4 and later.