Thats how my .axml looks like:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:paddingLeft="5dip"
android:textSize="18dp"
android:text="Kommentare"
style="?android:attr/listSeparatorTextViewStyle" />
As you see I'm accessing a style attribute that's defined in a style theme (?android:attr/listSeparatorTextViewStyle)
Now I would like to separate my own style:
<style name="TextViewTitleBar" parent="android:Theme">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingTop">2dip</item>
<item name="android:paddingBottom">2dip</item>
<item name="android:paddingLeft">5dip</item>
<item name="android:textSize">18dp</item>
</style>
and use it like:
style="#style/TextViewTitleBar" in my .axml , without losing the android defined style with the ? at the beginning.
How to combine/mix these styles?
You can set the parent to
#android:attr/listSeparatorTextViewStyle
Related
I want to create a style 100% equal to this button:
<com.google.android.material.button.MaterialButton
android:id="#+id/btn_xml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:backgroundTint="#color/red"
android:text="In XML"
android:textStyle="bold"
app:cornerRadius="25dp"
app:strokeColor="#color/black"
app:strokeWidth="2dp"/>
This is the style
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="btn_xml" value="btn_xml" />
<style name="ProgrammaticallyStyle">
<item name="android:id">#id/btn_xml</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">5dp</item>
<item name="android:backgroundTint">#color/red</item>
<item name="android:paddingStart">30dp</item>
<item name="android:paddingEnd">30dp</item>
<item name="android:text">In XML</item>
<item name="android:textStyle">bold</item>
<item name="app:cornerRadius">25dp</item>
<item name="app:strokeColor">#color/black</item>
<item name="app:strokeWidth">2dp</item>
</style>
</resources>
But in style, the last 3 attributes start with app:xxx and cannot be assigned. I assumed that is because in xml I have the following sentence in button parent view:
xmlns:app="http://schemas.android.com/apk/res-auto"
Using sttributes without app: doesn't work, do I maybe need a specific parent for the style?
How can I assign these app:xxx attributes in style?
I use one of the predefined styles for MaterialButton.
<com.google.android.material.button.MaterialButton
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Approve" />
And this is the style predefined style which i used.
</style>
<style name="Widget.MaterialComponents.Button.OutlinedButton" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:paddingLeft">#dimen/mtrl_btn_padding_left</item>
<item name="android:paddingRight">#dimen/mtrl_btn_padding_right</item>
<item name="strokeColor">#color/mtrl_btn_stroke_color_selector</item>
<item name="strokeWidth">#dimen/mtrl_btn_stroke_size</item>
</style>
And this is parent style of Widget.MaterialComponents.Button.OutlinedButton
<style name="Widget.MaterialComponents.Button.TextButton" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="android:textColor">#color/mtrl_text_btn_text_color_selector</item>
<item name="android:paddingLeft">#dimen/mtrl_btn_text_btn_padding_left</item>
<item name="android:paddingRight">#dimen/mtrl_btn_text_btn_padding_right</item>
<item name="iconTint">#color/mtrl_text_btn_text_color_selector</item>
<item name="iconPadding">#dimen/mtrl_btn_text_btn_icon_padding</item>
<item name="backgroundTint">#color/mtrl_btn_text_btn_bg_color_selector</item>
<item name="rippleColor">#color/mtrl_btn_text_btn_ripple_color</item>
</style>
Now i tried to override one of the attributes of Widget.MaterialComponents.Button.TextButton in my styles.xml
<style name="Widget.MaterialComponents.Button.TextButton">
<item name="android:textColor">#color/colorAccent</item>
</style>
I wonder whether this is the right approach or not to override a predefined style and will style Widget.MaterialComponents.Button.OutlinedButton use #color/colorAccent as text color. I think its working but i can not be sure is there any side effect of this approach or is there a better way ?
You can use one of the following:
<style name="MyCustomStyle" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="android:textColor">#color/colorAccent</item>
</style>
<style name="Widget.MaterialComponents.Button.OutlinedButton.MyCustomStyle">
<item name="android:textColor">#color/colorAccent</item>
</style>
With these approach, you would inherit all the properties of your parent style and you would be declare only those properties that you like to change/override.
And use this style in your layout file as follow:
<com.google.android.material.button.MaterialButton
style="#style/MyCustomStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Approve" />
or
<com.google.android.material.button.MaterialButton
style="#style/Widget.MaterialComponents.Button.OutlinedButton.MyCustomStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Approve" />
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"/>
styles.xml
<style name="Red" parent="android:TextAppearance.DeviceDefault.Medium.Inverse">
<item name="android:textColor">#f00</item>
</style>
<style name="Red.LARGE">
<item name="android:textSize">30sp</item>
</style>
When i use this;
<Button
android:id="#+id/save"
android:text="#string/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/save_marginTop"
android:gravity="center"
style="#style/Red.LARGE"/>
This button attribute only Large and doest painting to Red. Why?
Your Red.LARGE style needs to use the parent attribute. Red.LARGE will inherit Red if it is changed to:
<style name="Red.LARGE" parent="Red">
<item name="android:textSize">30sp</item>
</style>
I'm trying to make themes, I have asked myself, Is it possible to give the different colors for the particular textview.
Example: In "Theme.One", I will like in the textview "Title" the color Green and textview "text1" the color Pink.
Themes.xml
<style name="Theme.One" parent="#android:style/Theme.Light">
<item name="android:background">#color/Azur</item>
<item name="android:textColor">#color/Black</item>
...
</style>
<style name="Theme.Two" parent="#android:style/Theme.Light">
<item name="android:background">#color/Blue</item>
<item name="android:textColor">#color/White</item>
...
</style>
Interface.xml
<TextView
android:text="#string/Title"
android:id="#+id/Title"
android:textSize="25sp" />
<TextView
android:text="#string/text1"
android:id="#+id/text1"
android:textSize="20sp" />
I hope to have well formulated the sentences, and Thanking you in advance for answer,
Aziza
In the manifest:
android:theme="#style/myTheme"
In res/values folder :
<style parent="#android:style/Theme.Dialog" name="myTheme">
<item name="android:textColor">#00ff00</item>
<item name="android:dateTextAppearance">?android:attr/textAppearanceSmall</item>
</style>
you can change the color ti different color and apply the color for the textview.
android:textColor="yourcolor"
You should have one style for the pink and another one for green. For example
for the green TextView:
<TextView
android:text="#string/Title"
android:id="#+id/Title"
android:textSize="25sp"
style="#style/Colorgreen"
/>
and for the style you have
<style name="Colorgreen">
<item name="android:textColor">#00FF00</item>
</style>