Default font family not changing in android app - java

I am tried to change my font on entire app with Style.xml and it should change font everywhere on my app but i am getting same old font everywhere, only i see changes on dialog title not other places. Check the screenshot of app only no.2 screen dialog has changes. Can you please help me out. I am not able to get what wrong i am doing here.
Style.xml
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorPrimary">#color/primary</item>
<item name="colorAccent">#color/accent</item>
<item name="colorSurface">#color/white</item>
<item name="android:textColorPrimary">#color/primary_text</item>
<item name="android:textColorSecondary">#color/secondary_text</item>
<item name="android:divider">#color/divider</item>
<item name="windowActionBarOverlay">true</item>
<item name="fontFamily">#font/myfont</item>
<item name="android:fontFamily">#font/font_elaxer</item>
<item name="selectableItemBackground">?android:selectableItemBackground</item>
<item name="android:colorControlHighlight" tools:targetApi="lollipop">#color/ripplecolor</item>
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
<item name="android:textColorHint">#color/custom_hint_color</item>
<!-- enable window content transitions -->
<item name="android:windowActivityTransitions" tools:targetApi="lollipop">true</item>
<!-- specify enter and exit transitions -->
<item name="android:windowEnterTransition" tools:targetApi="lollipop">#transition/explode</item>
<item name="android:windowExitTransition" tools:targetApi="lollipop">#transition/explode</item>
<!--<item name="android:windowEnterTransition" tools:targetApi="lollipop">#android:transition/slide_right</item>
<item name="android:windowExitTransition" tools:targetApi="lollipop">#android:transition/slide_left</item>-->
<!-- specify shared element transitions -->
<item name="android:windowSharedElementEnterTransition" tools:targetApi="lollipop">#transition/change_image_transform</item>
<item name="android:windowSharedElementExitTransition" tools:targetApi="lollipop"> #transition/change_image_transform</item>
</style>
myfont.xml
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<font
app:fontStyle="normal"
app:fontWeight="400"
app:font="#font/dancing_r" />
<font
app:fontStyle="italic"
app:fontWeight="400"
app:font="#font/dancing_b" />
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="#font/dancing_r" />
<font
android:fontStyle="italic"
android:fontWeight="400"
android:font="#font/dancing_b" />
</font-family>

Related

Not able to see icons in side navigation bar in android studio

I'm not able to see the icons I am providing in the menu item to see it inside the navigation bar.
Below is the code of the menu main_menu.xml file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/home_nav" android:title="Home" android:icon="#drawable/home"/>
<item android:id="#+id/profile" android:title="Profile" android:icon="#drawable/profile"/>
<item android:id="#+id/generate_mpin" android:title="Generate Mpin" android:icon="#drawable/gen_mpin_icon"/>
<item android:id="#+id/history" android:title="My History" android:icon="#drawable/history_icon"/>
<item android:id="#+id/acc_statement" android:title="Account Statement" android:icon="#drawable/acc_stat_icon"/>
<item android:id="#+id/funds" android:title="Funds" android:icon="#drawable/funds_icon"/>
<item android:id="#+id/game_rates" android:title="Game Rates" android:icon="#drawable/game_rates_icon"/>
<item android:id="#+id/how_to_play" android:title="How To Play" android:icon="#drawable/how_to_play_icon"/>
<item android:id="#+id/settings" android:title="Settings" android:icon="#drawable/settings_icon"/>
<item android:id="#+id/logout" android:title="Logout" android:icon="#drawable/logout_icon"/>
</menu>
Below is the result I'm getting while using the above XML file:
What I getting:
What I expecting:

How to make customActionBar transparent and change its text colour?

I want to make the ActionBar transparent throughout the app and also change the text colour to white in the ActionBar. I tried setting the android:background to null but it had no effect. I am still getting a white ActionBar with Black text in the following code:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/app_white</item>
<!--item name="colorPrimaryDark">#color/colorPrimaryDark</item-->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<!--item name="colorAccent">#color/colorAccent</item-->
<item name="colorAccent">#1da1f2</item>
<!-- <item name="actionBarStyle">#style/MyActionBar</item>-->
<!-- <item name="android:actionBarStyle">#style/MyActionBar</item>-->
</style>
<style name="MyActionBar" parent="#android:style/Widget.ActionBar">
<item name="android:background">#null</item>
<item name="background">#null</item>
<item name="fontFamily">#font/mukta_bold</item>
<item name="titleTextStyle">#style/MyActionBarTitle</item>
<item name="actionMenuTextColor">#color/app_white</item>
</style>
<!-- <style name="MyActionBar.MenuTextStyle"-->
<!-- parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">-->
<!-- <item name="android:textColor">#color/app_light_black</item>-->
<!-- </style>-->
<style name="MyActionBarTitle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/app_white</item>
</style>
<style name="Switch_Style">
<item name="android:textColor">#000000</item>
<item name="android:textSize">15sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="CustomTheme" parent="Theme.MaterialComponents.Light.NoActionBar"/>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />
<style name="Widget.MyApp.MyButton" parent="Widget.MaterialComponents.Button">
<item name="backgroundTint">?attr/colorSecondary</item>
</style>
</resources>
You should use colorControlNormal flag in your Theme for AppBar
<style name="appBarTheme" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
</style>
and in your AppBarLayout use background as transparent
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:theme="#style/appBarTheme">
...........
</com.google.android.material.appbar.AppBarLayout
Make your BaseTheme of app as NoActionBar so you can create a custom action bar in your activity/fragment -
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
Happy Coding !!

How do I change the color of the timepicker in my Android app?

As you can see from the image below, I'm using the time picker in my app.
I need to change the color but don't know how...
Thanks for the help.
This can be easily achieved from xml (5.0+ only)
v21/themes.xml
<style name="Theme"
parent="MyTheme.Base">
<item name="android:dialogTheme">#style/Theme.Dialog</item> <!-- TimePicker dialog -->
<item name="android:alertDialogTheme">#style/Theme.Dialog</item> <!-- Alert dialog -->
</style>
<style name="Theme.Dialog"
parent="android:Theme.Material.Light.Dialog">
<item name="android:colorAccent">#color/...</item>
<item name="android:colorPrimary">#color/...</item>
<item name="android:colorPrimaryDark">#color/...</item>
</style>
Edit
Please note that as of Android Support Library 22.1.0 there is a new AppCompatDialog available! http://android-developers.blogspot.de/2015/04/android-support-library-221.html
Try this code
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TimePicker" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowIsFloating">true</item>
<item name="colorAccent">#color/primary</item>
<item name="colorControlActivated">#color/secondary</item>
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary</item>
<item name="android:buttonBarNegativeButtonStyle">#style/DatePickerTheme.ButtonBarButtonStyle</item>
<item name="android:buttonBarPositiveButtonStyle">#style/DatePickerTheme.ButtonBarButtonStyle</item>
</style>
<style name="DatePickerTheme.ButtonBarButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#color/primary</item>
</style>
</resources>
The first one is colorAccent, the second is colorControlActivated and the last one does not belong to the timepicker, it belongs to dialog so you should apply the an style similar to this post

TabBar Divider is not getting customised properly

I tried to customise the dividers between the tabs of the TabBar, but it seems that the customisation isn't working properly!
Here's the link to the screenshot: http://imgur.com/vhcwIGx
Here's my styles.xml file's code:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="android:actionBarTabTextStyle">#style/ActionBarTabTextStyle</item>
<item name="android:actionBarTabBarStyle">#style/ActionBarTabBarStyle</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/ActionBarStyle</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="actionBarTabTextStyle">#style/ActionBarTabTextStyle</item>
<item name="actionBarTabBarStyle">#style/ActionBarTabBarStyle</item>
</style>
<!-- ActionBar styles -->
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Customize your theme here. -->
<item name="android:background">#color/light_purple</item>
<!-- Support library compatibility -->
<item name="background">#color/light_purple</item>
</style>
<!-- ActionBar tabs styles -->
<style name="ActionBarTabStyle" parent="#style/Widget.AppCompat.Light.ActionBar.TabView">
<!-- tab indicator -->
<item name="android:background">#drawable/actionbar_tab_indicator</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_tab_indicator</item>
</style>
<!-- ActionBar tabsText styles -->
<style name="ActionBarTabTextStyle" parent="#style/Widget.AppCompat.Light.ActionBar.TabBar">
<!-- text style -->
<item name="android:textColor">#color/light_purple</item>
<item name="android:textStyle">bold</item>
</style>
<!-- Action bar tab bar style -->
<style name="ActionBarTabBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar.TabBar">
<item name="android:showDividers">middle</item>
<item name="android:divider">#drawable/divider_style</item>
<item name="android:dividerPadding">8dp</item>
<!-- Support library compatibility -->
<item name="showDividers">middle</item>
<item name="divider">#drawable/divider_style</item>
<item name="dividerPadding">8dp</item>
</style>
<style name="WalkthroughThemes" parent="Theme.AppCompat.Light.NoActionBar">
</style>
</resources>
Here's my divider_style.xml file's code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="1.5dp" android:right="1.5dp" android:drawable="#color/light_purple">
<shape android:shape="line" android:tint="#color/light_purple">
</shape>
</item>
</layer-list>
I am unable to figure out what to do here.
Please let me know what to do.
I'm new to StackOverflow, so please cooperate.
Thanks in advance.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="0dp" android:right="0dp" android:bottom="1dp" android:drawable="#color/light_purple">
<shape android:shape="line" android:tint="#color/light_purple">
</shape>
</item>
</layer-list>

How to apply a buttonStyle in Android?

I have this Theme,
<style name="AppTheme" parent="#style/AppBaseTheme">
<item name="android:buttonStyle">#style/MyButtonStyle</item>
</style>
I need to define another style for a button (called MyButtonStyleDealer).
Using the following code I get error android:buttonStyle has been already defined.
<style name="AppTheme" parent="#style/AppBaseTheme">
<item name="android:buttonStyle">#style/MyButtonStyle</item>
<item name="android:buttonStyle">#style/MyButtonStyleDealer</item>
</style>
I would like to know if it possible define a second style for the button and how to apply it to the View.
If got your question correctly, you can add inside your style file another entry for the button
<style name="MyNotClickableButtonStyle">
<item name="android:background">#drawable/my_button_background</item>
<item name="android:clickable">false</item>
</style>
and inside your layout,
<Button
style="#style/MyNotClickableButtonStyle"
You only can define one android:buttonStyle. If you want to change only this the button style has to add another style.
Another properties can be used if you want but only once.
For instance:
<style name="GlobalAppTheme" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:editTextStyle">#style/GlobalTextView</item>
<item name="android:textColor">#color/text_gray</item>
<item name="android:checkboxStyle">#style/CheckBox</item>
<item name="android:radioButtonStyle">#style/RadioButton</item>
<item name="android:buttonStyle">#style/Button</item>
<item name="android:textSize">14sp</item>
<item name="android:actionBarItemBackground">#android:color/transparent</item>
<item name="actionBarItemBackground">#android:color/transparent</item>
<item name="android:alertDialogStyle">#style/Theme.Sherlock.Light.Dialog</item>
</style>
<style name="GlobalAppTheme2" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:editTextStyle">#style/GlobalTextView</item>
<item name="android:textColor">#color/text_gray</item>
<item name="android:checkboxStyle">#style/CheckBox</item>
<item name="android:radioButtonStyle">#style/RadioButton</item>
<item name="android:buttonStyle">#style/Button</item>
<item name="android:textSize">14sp</item>
<item name="android:actionBarItemBackground">#android:color/transparent</item>
<item name="actionBarItemBackground">#android:color/transparent</item>
<item name="android:alertDialogStyle">#style/Theme.Sherlock.Light.Dialog</item>
</style>
You can set sepecific styles like this:
<Button
android:id="#+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:onClick="sendMessage"
style="?android:attr/MyButtonStyleDealer" />

Categories