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" />
Related
This is my EditText's selection mode style.
As you can see it's texts are not completely visible.
This is my styles.xml file:
<style name="MyApp" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
<item name="colorOnPrimary">#color/onPrimary</item>
<item name="colorSecondary">#color/secondary</item>
<item name="colorSecondaryVariant">#color/secondaryLight</item>
<item name="colorOnSecondary">#color/onSecondary</item>
<item name="colorError">#color/error</item>
<item name="colorOnError">#color/onError</item>
<item name="colorSurface">#color/surface</item>
<item name="android:textViewStyle">#style/DefaultTextStyle</item>
<item name="buttonStyle">#style/DefaultButtonStyle</item>
<item name="materialButtonStyle">#style/DefaultButtonStyle</item>
<item name="android:textColorPrimary">#color/enabledColor</item>
<item name="bottomSheetDialogTheme">#style/BottomSheetTheme</item>
<item name="textAppearanceBody1">#style/BodyAppearance</item>
<item name="textAppearanceSubtitle1">#style/Subtitle1Appearance</item>
<item name="textAppearanceSubtitle2">#style/Subtitle2Appearance</item>
<item name="textAppearanceButton">#style/ButtonAppearance</item>
<item name="textAppearanceHeadline1">#style/Headline1</item>
<item name="textAppearanceCaption">#style/Caption</item>
<item name="popupMenuStyle">#style/PopupMenuStyle</item>
<item name="transparentPrimaryColor">#color/transparentPrimary</item>
<item name="colorOnSurface">#color/onSurface</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowNoTitle">true</item>
<item name="actionModeBackground">?attr/colorSecondary</item>
<item name="actionBarTheme">#style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
<item name="android:popupWindowStyle">#style/PopupWindodwStyle</item>
</style>
I found out that deleting textAppearanceButton attribute somehow fixes the problem. This is how the value of textAppearanceButton look like:
<style name="ButtonAppearance" parent="MyApp">
<item name="fontFamily">#font/iransans_bold</item>
<item name="android:textSize">14sp</item>
</style>
I cannot delete that attribute because I've used it throughout my application. Does anyone know why this problem happens? Thanks.
Here is a dialog, how to change this color (unchecked)?
I try to set style but not work:
<style name="ThemeMyAppDialogAlertDay"
parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="colorPrimary">#color/color_secondary</item>
<item name="colorPrimaryVariant">#color/color_primary_variant</item>
<item name="colorOnPrimary">#color/color_secondary</item>
<item name="colorSecondary">#color/color_secondary</item>
<item name="colorAccent">#color/color_error</item>
</style>
You can use:
<style name="ThemeMyAppDialogAlertDay"
parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="colorSecondary">#color/selected</item> <!-- selected -->
<item name="colorControlNormal">#color/unselected</item> <!-- unselected -->
</style>
Try this , It should help
<style name="materialDiaog" parent="MaterialAlertDialog.MaterialComponents">
<item name="buttonTint">#color/colorPrimary</item>
<item name="colorPrimary">#color/color_secondary</item>
<item name="colorPrimaryVariant">#color/color_primary_variant</item>
<item name="colorOnPrimary">#color/color_secondary</item>
<item name="colorSecondary">#color/color_secondary</item>
<item name="colorAccent">#color/color_error</item>
</style>
<style name="AppTheme" parent="{set your parent theme here}">
<item name="materialAlertDialogTheme">#style/materialDiaog</item>
</style>
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 !!
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>
Option Menu show incorrectly on Custom Style map
The problem raised on an application in android
I have a custom theme on my app. The problem is that the option menu shows incorrectly ,so the option menu shows cut of on the screen.
I wondering why could happen?
This is my style file xml
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:typeface">normal</item>
<item name="android:typeface">sans</item>
<item name="android:typeface">serif</item>
<item name="android:typeface">monospace</item>
<item name="android:actionBarItemBackground">#drawable/selectable_background_example</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Example</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Example</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.Example</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Example</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Example</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_example</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_example</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Example</item>
</style>
<style name="ActionBar.Solid.Example" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid_example</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_example</item>
<item name="android:backgroundSplit">#drawable/ab_bottom_solid_example</item>
<item name="android:progressBarStyle">#style/ProgressBar.Example</item>
</style>
<style name="ActionBar.Transparent.Example" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/ab_transparent_example</item>
<item name="android:progressBarStyle">#style/ProgressBar.Example</item>
</style>
<style name="PopupMenu.Example" parent="#android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
</style>
<style name="DropDownListView.Example" parent="#android:style/Widget.Holo.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_example</item>
</style>
<style name="ActionBarTabStyle.Example" parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_example</item>
</style>
<style name="DropDownNav.Example" parent="#android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#drawable/spinner_background_ab_example</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
<item name="android:dropDownSelector">#drawable/selectable_background_example</item>
</style>
<style name="ProgressBar.Example" parent="#android:style/Widget.Holo.Light.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_example</item>
</style>
<style name="ActionButton.CloseMode.Example" parent="#android:style/Widget.Holo.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_example</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Example.Widget" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu.Example</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Example</item>
</style>
For any ones that have this same trouble, the solution , in my case , was solved by added this line in the manifest file.
<supports-screens
android:anyDensity="true" />