ImageButtons aren't taking attributes from theme styles - java

My ImageButtons don't seem to be affected by the parameters set out in the style document, however other Buttons are when I define their style in the exact same way.
This is a condensed version of my styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:buttonStyle">#style/Button</item>
<item name="android:imageButtonStyle">#style/ImageButton</item>
</style>
<style name="Button" parent="#android:style/Widget.Button">
<item name="android:background">#color/icons</item>
</style>
<style name="ImageButton" parent="#android:style/Widget.ImageButton">
<item name="android:background">#color/icons</item>
</style>
When using these styles (I've tried it with other items however none seem to work), normal Buttons will take the color of #color/icons, however ImageButtons don't. They also remain unaffected when their styles are set individually with style="#style/ImageButton", however if I set the background directly with android:background="#color/icons" on each button it does have an affect.

Use
style="#style/ImageButton"
in your button body like:`
<Button
style="#style/button_theme"
android:text="Sign In"
android:id="#+id/id" />`
this is the button style
<style name="button_theme">
<item name="android:background">#drawable/button_shape</item>
<!--<item name="android:padding">5dp</item>-->
<item name="android:textColor">#ffffff</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>

OR you can use these styles in your theme like you shown above
just add this line
:-
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:buttonStyle">#style/Button</item>
<item name="buttonStyle">#style/Button</item>
<item name="android:imageButtonStyle">#style/ImageButton</item>
</style>
<style name="Button" parent="#android:style/Widget.Button">
<item name="android:background">#color/icons</item>
</style>
<style name="ImageButton" parent="#android:style/Widget.ImageButton">
<item name="android:background">#color/icons</item>
</style>

Related

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 to change the color of an dialog item from black to white?

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 to customize colors and other things of the date range picker of material component?

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>

Android AppCompat ToolBar color can't be changed to white

I attempted the following:
<style name="myAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text_color</item>
</style>
To change my toolbar text color to white, but it's still black!
What do I need to change?
Are you sure that you are using Toolbar? If yes, then your myAppTheme should extend from Theme.AppCompat.NoActionBar ... Toolbar is a replacement of ActionBar. Therefore if you want to use it then you must remove ActionBar styles from your xml.
I suggest you read this blog post. And here is a nice implementation on how to change title color.

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