Hi I'm trying to make simple Android app.
I want to make my app changing it's font depending on the language of users.
but I don't know how to change <item> in styles.xml.
I set font at values/styles.xml like below
<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="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:textViewStyle">#style/Customfont1</item>
<item name="android:buttonStyle">#style/Customfont2</item>
<item name="android:editTextStyle">#style/Customfont3</item>
</style>
<style name="Customfont1" parent="#android:style/Widget.DeviceDefault.TextView">
<item name="android:fontFamily">#font/bmjua</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textAlignment">center</item>
and need to change
<item name="android:fontFamily">#font/bmjua</item> part to
<item name="android:fontFamily">#font/roundbold</item>
when local language is Japanese.
I use code below
Locale syslocal = getApplicationContext().getResources().getConfiguration().locale;
String curLanguate = ((Locale) syslocal).getLanguage();
to get local language code and What I can't do now is
'if(curLanguate=="ja"){
"change '<item name="android:fontFamily">#font/bmjua</item> ' to
'<item name="android:fontFamily">#font/roundbold</item> '
by changing'styles.xml'file.
}
what I have to do? to make this possible?!
Related
I'm using the following theme for my dialog:
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorSecondary">#color/colorWhite</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:background">#color/colorPrimary</item>
<item name="android:textColor">#color/colorWhite</item>
<item name="android:textColorAlertDialogListItem">#color/colorWhite</item>
</style>
Everything works but the item text color. I need to be white, but for some reason, it remains back. How can I change that text to be white? Thanks
Edit:
Here is my AppTheme:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorSecondary">#color/colorWhite</item>
</style>
You may refer AlertDialog Theme: How to change item text color?
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="textColorAlertDialogListItem">#color/colorWhite</item>
</style>
or
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="alertDialogTheme">#style/AlertDialogStyle </item>
</style>
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
...
<item name="textColorAlertDialogListItem">#color/colorWhite</item>
<!--
<item name="android:textColor">#color/colorWhite</item>
-->
</style>
Also you can change android:textColor, but it will change all the text color in Dialog Window
Use your custom DialogBox Style while creating DialogBox.
new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AlertDialogStyle))
Add these lines into your app theme
<item name="android:alertDialogTheme">#style/AlertDialogStyle</item>
<item name="android:alertDialogStyle">#style/AlertDialogStyle</item>
How I can change the color of the header only in date range picker, I search didnt find exactly how, I just know how to change the color of all date range picker with changing the color of the colorPrimary and that will change the color of all the header and the selected dates, I want to change only the header color
and also if there is a way to change the size of title text, I know we can change the title but can we change the title size?
this is what I tried in style
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/shamrock_green</item>
<item name="colorPrimaryDark">#color/shamrock_green_dark</item>
<item name="colorAccent">#color/shamrock_green</item>
<item name="colorButtonNormal">#color/shamrock_green</item>
<item name="colorOnSecondary">#color/white</item>
<item name="colorOnSurface">#android:color/transparent</item>
<item name="bottomSheetDialogTheme">#style/AppBottomSheetDialogTheme</item>
<item name="materialCalendarFullscreenTheme">#style/CustomThemeOverlay_MaterialCalendar_Fullscreen</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorOnSurface">#android:color/black</item>
<item name="colorPrimary">#color/black</item>
</style>
<style name="CustomThemeOverlay_MaterialCalendar_Fullscreen"
parent="#style/ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen">
<item name="materialCalendarStyle">#style/Custom_MaterialCalendar.Fullscreen</item>
</style>
<style name="Custom_MaterialCalendar.Fullscreen"
parent="#style/Widget.MaterialComponents.MaterialCalendar.Fullscreen">
<item name="android:windowFullscreen">false</item>
<item name="android:headerBackground">#color/shamrock_green</item>
</style>
<style name="ThemeMaterialCalendarButton" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#color/shamrock_green</item>
</style>
<style name="ThemeMaterialCalendarTextButton" parent="Widget.MaterialComponents.Button.TextButton.Dialog.Flush">
<item name="android:textColor">#color/shamrock_green</item>
<item name="iconTint">#color/shamrock_green</item>
</style>
<style name="AppTheme.FullScreen" parent="#style/Theme.AppCompat">
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
the thing that works now is its shows as dialog not full screen which what I want, but no text and background colors changes, the only way to change colors changes the colors like colorPrimary and these colors will affect all app
You can use a theme overlay:
MaterialDatePicker.Builder<Pair<Long, Long>> builderRange =
MaterialDatePicker.Builder.dateRangePicker();
builderRange.setTheme(R.style.CustomMaterialCalendarTheme);
with:
<style name="CustomMaterialCalendarTheme" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">
<!-- Header Layout -->
<item name="materialCalendarHeaderLayout">#style/customHeaderLayout</item>
<!-- Header title -->
<item name="materialCalendarHeaderTitle">#style/customHeaderTitle</item>
<!-- Header selection title -->
<item name="materialCalendarHeaderSelection">#style/CustomHeaderSelection</item>
</style>
<style name="customHeaderLayout" parent="#style/Widget.MaterialComponents.MaterialCalendar.HeaderLayout">
<item name="android:background">#color/.....</item>
</style>
<style name="customHeaderTitle" parent="#style/Widget.MaterialComponents.MaterialCalendar.HeaderTitle">
<item name="android:textAppearance">#style/customTextAppearance</item>
</style>
<style name="customTextAppearance" parent="#style/TextAppearance.MaterialComponents.Overline">
<item name="android:textSize">xxsp</item>
</style>
<style name="CustomHeaderSelection" parent="Widget.MaterialComponents.MaterialCalendar.HeaderSelection">
<item name="android:textSize">xxsp</item>
</style>
I'm currently working on creating a custom theme for a datePicker and I'm having some difficulty with setting the headerBackground and the circle around the selected date separately. I've set my theme up like this:
<style name="State0DatePickerTheme" parent="AppTheme">
<item name="colorAccent">#color/state0Dark</item>
<item name="android:headerBackground">#color/state0Primary</item>
</style>
App theme looks like this:
<style name="AppTheme" parent="State0BaseTheme">
<item name="colorPrimary">#color/state0Primary</item>
<item name="colorPrimaryDark">#color/state0Dark</item>
<item name="android:statusBarColor">#color/state0Primary</item>
<item name="android:colorControlNormal">#color/colorAccent</item>
<item name="android:background">#color/state0Primary</item>
<item name="android:textColorPrimary">#color/colorAccent</item>
</style>
And last but not least, State0BaseTheme looks like this:
<style name="State0BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/state0Primary</item>
<item name="colorPrimaryDark">#color/state0Dark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor">#color/state0Primary</item>
<item name="android:colorControlNormal">#color/colorAccent</item>
<item name="android:background">#color/state0Primary</item>
<item name="android:textColorPrimary">#color/colorAccent</item>
</style>
I had thought that overriding colorAccent, and setting headerBackground would work just fine, but I guess not? Here's what it looks like with all these styles:
If I set android:headerBackground in the xml of the datePicker, everything works great. However, I want to be able to change the theme for all screens of the app based on user input. Thoughts as to why this isn't working?
I read the link posted by #DasserBasyouni and found that making the parent of my datePickerTheme #android:style/Widget.Material.Light.DatePicker and setting android:datePickerStyle to #style/State0DatePickerTheme in State0BaseTheme worked perfectly
So in the app I am making, I have both a dark and light theme. The light theme works fine, but the alert dialogs I have still show the background the same as the light theme. Since it is dark, the text changes to light and the user can't see anything. Is there a certain attribute I need to change?
Here is the styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#E53935</item>
<item name="colorPrimaryDark">#C62828</item>
<item name="android:navigationBarColor">#E53935</item>
<item name="android:colorAccent">#1565C0</item>
<item name="android:colorForeground">#color/foreground_material_light</item>
<item name="android:colorBackground">#color/background_material_light</item>
<!-- Other attributes -->
</style>
<style name="Dark" parent="#style/AppTheme" >
<item name="android:colorForeground">#color/foreground_material_dark</item>
<item name="android:colorPrimary">#color/primary_material_dark</item>
<item name="android:colorPrimaryDark">#color/primary_dark_material_dark</item>
<item name="android:colorAccent">#color/accent_material_dark</item>
<item name="android:navigationBarColor">#color/primary_material_dark</item>
<item name="android:colorBackground">#color/background_material_dark</item>
<item name="android:textColorPrimary">#android:color/primary_text_dark</item>
<item name="android:textColorPrimaryInverse">#android:color/primary_text_light</item>
<item name="android:textColorSecondary">#android:color/secondary_text_dark</item>
<item name="android:textColorSecondaryInverse">#android:color/secondary_text_light</item>
<item name="android:textColorTertiary">#android:color/tertiary_text_dark</item>
</style>
Here is what it shows up as:
Solved: You need to create your own xml like this:
<item name="alertDialogTheme">#style/DarkAlertDialog</item>
With this being your custom dialog:
<style name="DarkAlertDialog" parent="Theme.AppCompat.Dialog">
<item name="background">#color/background_material_dark</item>
</style>
Use the parent AppCompat and then use colorPrimary and colorAccent properties (without an Android prefix) to theme things.
Right now the styles are coming from a dialog subtheme and not being affected by these style definitions.
How can i apply a custom ActiobbarSherlock to my activities. I am looking for something like this this. I know the four square application uses the SherlockActionBar how can i do this?
This is my current style ...
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#449def</item>
<item name="background">#0099CC</item>
<item name="android:titleTextStyle">#style/Theme.ActionBar.TitleTextStyle</item>
<item name="icon">#drawable/ic_launcher</item>
<item name="backgroundSplit">#drawable/gray_seprator</item>
<item name="android:displayOptions">showTitle|homeAsUp</item>
<item name="displayOptions">showTitle|homeAsUp</item>
</style>
Kind Regards