I am trying to apply custom theme to remove extra space around checkbox using style.
But my style is note getting applied.
<com.google.android.material.checkbox.MaterialCheckBox
android:id="#+id/checkbox"
style="#style/TestCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="#id/title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
<!-- Style -->
<style name="TestCheckBox" parent="Widget.MaterialComponents.CompoundButton.CheckBox">
<item name="minWidth">0dp</item>
<item name="minHeight">0dp</item>
</style>
Not sure what is going wrong
This style add on your app theme
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<!-- .... -->
<item name="checkboxStyle">#style/TestCheckBox</item>
</style>
Related
I've used MaterialButton but my expected design not came. Below my xml code and style.
I've need white color of the background instead of the orange color, what I can do to achieve this. Please provide your suggestion.
// Material Design version I've used
implementation 'com.google.android.material:material:1.2.1'
**Color primary** means orange color.
<com.google.android.material.button.MaterialButton
android:id="#+id/btnWatchVideo"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="#string/watch_video"
android:textColor="#color/colorBlack"
android:visibility="visible"
app:strokeColor="#color/colorBlack"
app:strokeWidth="2dp" />
<style name="SliderThemeBlack" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorBlack</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:screenOrientation">portrait</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
Manifest:
<activity android:name="xxx"
android:theme="#style/SliderThemeBlack" android:windowSoftInputMode="stateHidden" />
use app:backgroundTint="#color/white" to your MaterialButton
At the moment, I feel a little bit stupid.
Here's my problem :
I actually want to apply different styles for some buttons, different from my default button's style.
My styles.xml :
<!-- Base application theme. -->
<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>
</style>
<style name="CustomTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/CustomTheme.ActionBarStyle</item>
<item name="cardViewStyle">#style/CustomTheme.CardViewStyle</item>
<item name="buttonStyle">#style/CustomTheme.StandardButton</item>
</style>
<...>
<style name="CustomTheme.StandardButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="background">#drawable/ripple_button</item>
<item name="android:tint">#color/white</item>
<item name="android:elevation">8dp</item>
</style>
<style name="CustomTheme.ConfirmButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="background">#drawable/ripple_button_confirm</item>
<item name="android:tint">#color/white</item>
<item name="android:elevation">8dp</item>
</style>
<style name="CustomTheme.CancelButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="background">#drawable/ripple_button_cancel</item>
<item name="android:tint">#color/white</item>
<item name="android:elevation">8dp</item>
</style>
</resources>
In fact, I tried a lot of things with inheritance of my CustomTheme.ConfirmButton and CustomTheme.CancelButton.
What's changing from CustomTheme.StandardButton : the shape's color.
The ripple_button.xml is orange.
Then, I created two other ripple buttons, the first one is red (CancelButton), the second one is green (ConfirmButton).
By default, the <item name="buttonStyle">#style/CustomTheme.StandardButton</item> is applied.
But, in my activity, even when I declare a specific theme to my buttons, the default style is the only one applied.
Note : the both buttons are always visible in these activity.
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_confirm_reset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/lbl_confirm"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#id/btn_cancel_reset"
android:layout_marginBottom="8dp"
style="#style/CustomTheme.ConfirmButton"/>
<Button
android:id="#+id/btn_cancel_reset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/lbl_cancel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="#id/btn_confirm_reset"
android:layout_marginBottom="8dp"
style="#style/CustomTheme.CancelButton"/>
</android.support.constraint.ConstraintLayout>
I tried to apply the "default" StandardButton theme manually for each button (and then by removing the line <item name="buttonStyle">#style/CustomTheme.StandardButton</item> from my styles.xml but I still get the same behavior : all my buttons are always orange (and using StandardButton theme).
So I'm wondering where I fail / what I don't understand, or even if it's possible.
If a peaceful soul has an idea, some tips, I will be grateful (I can thank my hero with a french craft beer).
Have a great day, and thanks for reading.
Update your Button Style as below:
style.xml
<style name="CustomTheme.StandardButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="android:backgroundTint">#color/orange</item>
<item name="android:colorButtonNormal">#color/gray</item>
<item name="android:colorControlHighlight">#color/blue</item>
<item name="android:elevation">8dp</item>
</style>
<style name="CustomTheme.ConfirmButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="android:backgroundTint">#color/orange</item>
<item name="android:colorButtonNormal">#color/gray</item>
<item name="android:colorControlHighlight">#color/blue</item>
<item name="android:elevation">8dp</item>
</style>
<style name="CustomTheme.CancelButton" parent="Base.Widget.AppCompat.Button.Colored">
<item name="android:backgroundTint">#color/orange</item>
<item name="android:colorButtonNormal">#color/gray</item>
<item name="android:colorControlHighlight">#color/blue</item>
<item name="android:elevation">8dp</item>
</style>
You missed to append android: in item background.
To set Ripple effect you have to use android:colorControlHighlight because android:backgroundTint will take only color as input and drawable will not work. Here android:colorButtonNormal will give no effect because we have set backgroundTint. If you will remove backgroundTint, it will take color from android:colorButtonNormal
You have to set the theme in Button instead of style.
your_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_confirm_reset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/lbl_confirm"
android:textColor="#color/white"
android:theme="#style/CustomTheme.ConfirmButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#id/btn_cancel_reset"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/btn_cancel_reset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/lbl_cancel"
android:textColor="#color/white"
android:theme="#style/CustomTheme.CancelButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="#id/btn_confirm_reset"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Hope it will work!!
I've been trying to change the color of the progressBar, and i've noticed it's using the accentColor (which is Blue in my case) and i've been trying to change it without luck.
Am I missing something?
This is in my styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="searchViewStyle">#style/AppTheme.SearchView</item>
<item name="editTextColor">#android:color/white</item>
<item name="actionBarStyle">#style/AppTheme.ActionBarStyle</item>
<item name="actionOverflowButtonStyle">#style/AppTheme.OverFlowItem</item>
<item name="colorPrimary">#color/ColorPrimary</item>
<item name="colorPrimaryDark">#color/ColorPrimaryDark</item>
<item name="colorAccent">#color/ColorPrimaryDark</item>
</style>
This is my element in the layout.xml
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="#style/Widget.AppCompat.ProgressBar"
android:id="#+id/progressBar01"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:indeterminate="true"/>
My activity:
public class MainActivity extends android.support.v7.app.AppCompatActivity
If you want to change accent color for one specific view you need to create style own style and set it to the view using android:theme attribute.
UPDATED
<style name="CustomProgressBarTheme" parent="Widget.AppCompat.ProgressBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimaryCutom</item>
<item name="colorPrimaryDark">#color/colorPrimaryDarkCustom</item>
<item name="colorAccent">#color/colorAccentCustom</item>
</style>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:theme="#style/CustomProgressBarTheme"
android:id="#+id/progressBar01"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:indeterminate="true"/>
try this
progressBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.ColorPrimaryDark), Mode.SRC_IN);
Since you have colorAccent with that color, you will need to change the ProgressBar's color with this:
android:progressBackgroundTint="#a31212" // your color
As the doc says:
Tint to apply to the progress indicator background.
Finally:
<ProgressBar
android:id="#+id/progressBar01"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="120dp"
android:progressBackgroundTint="#a31212" />
i want to change default theme of radio button to custom but it's not changing the theme. please help me out
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="android:radioButtonStyle">#style/radionbutton</item>
</style>
<!-- custom style -->
<style name="radionbutton"
parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:button">#drawable/radiobutton_drawable</item>
</style>
radiobutton_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="false" android:drawable="#mipmap/radio_unselected" >
</item>
<item android:state_checked="true" android:drawable="#mipmap/radio_selected">
</item>
Declare custom style in your styles.xml file.
<style name="MyRadioButton" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">#color/indigo</item>
<item name="colorControlActivated">#color/pink</item>
</style>
Apply this style to your RadioButton via android:theme attribute.
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Radio Button"
android:theme="#style/MyRadioButton"/>
only if your activity extends AppCompatActivity
Finally, i found answer by myself
I just create custom layout and add to ListAdapter object
radiobuttonlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/checkedTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="#drawable/radiobutton_drawable"
android:gravity="center_vertical"
android:text="New CheckedTextView"
android:padding="#dimen/dp10"
android:textColor="#color/white" />
Java file code
ListAdapter listAdapter = new ArrayAdapter<String> (context,R.layout.radiobuttonlayout,aryStrLockscreens);
listview_lockscreen.setAdapter(listAdapter);
It's worked for me.
The radiobutton_drawable.xml has a missing </selector> tag in the end.
Plus you should do this to your radio button-
<RadioButton android:layout_width="wrap_content"
android:layout_marginTop="20dp"
android:id="#+id/radio"
style="#style/radionbutton"
android:layout_height="wrap_content"/>
Sure you can do it in the parent AppTheme just do the following:
First you will Use the MaterialTheme as your parent theme:
<style name="AppTheme" parent="Theme.MaterialComponents.*">
Then create your RadioButton style in res/values/styles
<style name="Widget.App.RadioButton" parent="Widget.MaterialComponents.CompoundButton.RadioButton">
<item name="buttonTint">#color/white</item>
//put any thing here
</style>
Add it to Parent AppTheme
<style name="AppTheme" parent="Theme.MaterialComponents.*">
<item name="radioButtonStyle">#style/Widget.App.RadioButton</item>
</style>
Then Use it in your layout like:
<com.google.android.material.radiobutton.MaterialRadioButton
android:id="#+id/rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi"
/>
for more details about theming Theming RadioButton
Need to apply individual style to radio button
<RadioButton
android:layout_width="wrap_content"
style="#style/radiobutton_drawable"
android:layout_height="wrap_content"/>
You could add this to your styles.xml
<style name="Widget.Styles.Radio.RadioButton"
<item name="android:textAppearance">#style/ANY_TYPOGRAPHY_STYLE</item>
</style>
ANY_TYPOGRAPHY_STYLE is for example:
TextAppearance.MaterialComponents.Caption if you are using the Material theme
TextAppearance.AppCompat.Caption if you are using AppCompat theme.
OR any typography style you have created
Example:
<style name="TextAppearance.TypographyStyles.Body2" parent="TextAppearance.MaterialComponents.Body2">
<item name="fontFamily">#font/poppins_regular</item>
<item name="android:fontFamily">#font/poppins_regular</item>
<item name="android:textSize">14sp</item>
</style>
And use the radio button style as a style for the MaterialRadioButton or RadioButton
<com.google.android.material.radiobutton.MaterialRadioButton
style="#style/Widget.Styles.Radio.RadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEXT"/>
I got this style in XML:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/teal_500</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/teal_700</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#color/light_blue_500</item>
<!-- needed to suppress the old ActionBar when using the new Toolbar -->
<item name="android:windowActionBar">false</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight & colorSwitchThumbNormal. -->
</style>
</resources>
Question:
And inside the XML of a Fragment I'm using TextView onto which I would like to assign "colorPrimary" from the theme. But how?
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_input"
android:textColor="#android:color/black" <!-- use theme color here-->
android:fontFamily="sans-serif-bold"
android:text="some text"
android:textSize="24dp"/>
You can use like this
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_input"
android:textColor="?attr/colorPrimary"
android:fontFamily="sans-serif-bold"
android:text="some text"
android:textSize="24dp"/>