How can I give bold and normal styles inside our styles.xml?
The code which I have given is:
<style name="textbold" parent="#android:style/TextAppearance">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textstyle">bold</item>
</style>
<style name="textregular" parent="#android:style/TextAppearance">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textstyle">normal</item>
</style>
But its showing error over here: <item name="android:textstyle">
That's because it's textStyle, not textstyle. The attributes are case-sensitive.
<item name="android:textStyle">normal</item>
Related
I want to make a back button with the styles like:
<style name="back_button" parent="Widget.AppCompat.Button.Borderless">
<item name="android:fontFamily">#font/frutiger_light</item>
<item name="android:textColor">#color/lightSaber</item>
<item name="android:textSize">16sp</item>
<item name="android:textAllCaps">false</item>
<item name="android:text">#string/back</item>
<item name="android:background">#android:color/transparent</item>
</style>
But right now I already have one exited style:
<style name="FrutigerLight16LightSaber">
<item name="android:fontFamily">#font/frutiger_light</item>
<item name="android:textColor">#color/lightSaber</item>
<item name="android:textSize">16sp</item>
</style>
So I want to add a new style with Widget.AppCompat.Button.Borderless and FrutigerLight16LightSaber.
I tried two solutions by combing . and parent, but doesn't work.
ONE:
<style name="FrutigerLight16LightSaber.Borderless" parent="Widget.AppCompat.Button.Borderless">
</style>
then
<style name="back_button" parent="FrutigerLight16LightSaber.Borderless">
<item name="android:textAllCaps">false</item>
<item name="android:text">#string/back</item>
<item name="android:background">#android:color/transparent</item>
</style>
in this way, I lost FrutigerLight16LightSaber style.
TWO
<style name="FrutigerLight16LightSaberBorderless" parent="FrutigerLight16LightSaber">
<item name="android:borderlessButtonStyle">#style/Widget.AppCompat.Button.Borderless</item>
</style>
then
<style name="back_button" parent="FrutigerLight16LightSaberBorderless">
<item name="android:textAllCaps">false</item>
<item name="android:text">#string/back</item>
<item name="android:background">#android:color/transparent</item>
</style>
this way I lost Widget.AppCompat.Button.Borderless.
Thanks for any help!
Try using
<style name="FrutigerLight16LightSaber.Borderless" parent="Widget.AppCompat.Button.Borderless">
<item name="android:fontFamily">#font/frutiger_light</item>
<item name="android:textColor">#color/lightSaber</item>
<item name="android:textSize">16sp</item>
</style>
And then use like below:
<style name="back_button" parent="FrutigerLight16LightSaber.Borderless">
<item name="android:textAllCaps">false</item>
<item name="android:text">#string/back</item>
<item name="android:background">#android:color/transparent</item>
</style>
<style name="button" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="android:gravity">center</item>
<item name="android:layout_height">#dimen/button_height</item>
<item name="android:layout_width">wrap_content</item>
<item name="cornerRadius">#dimen/button_round_radius</item>
</style>
<style name="button.wide" parent="button">
<item name="android:fontFamily">#font/montserrat_regular</item>
<item name="android:layout_width">match_parent</item>
I do this in style file. but when I apply the style in layout. style="#style/button.wide"
the font doesn't work.
try using android:theme="#style/button.wide"
Change button style name and parent like, name="ButtonViewStyle"
and parent="android:Widget.Button"
<style name="ButtonViewStyle" parent="android:Widget.Button">
<item name="android:fontFamily">#font/montserrat_regular</item>
<item name="android:layout_width">match_parent</item>
</style>
Use <item name="android:buttonStyle">#style/ButtonViewStyle</item> line to your parent style
<style name="button" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="android:gravity">center</item>
<item name="android:layout_height">#dimen/button_height</item>
<item name="android:layout_width">wrap_content</item>
<item name="cornerRadius">#dimen/button_round_radius</item>
<item name="android:buttonStyle">#style/ButtonViewStyle</item>
</style>
What parent style should I use if I want to set global textViewStyle and maintain backward compatibility with AppCompat? I can't find something like Widget.AppCompat.TextView :
<style name="Base_AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textViewStyle">#style/GlobalTextViewStyle</item>
</style>
<style name="GlobalTextViewStyle" parent="?????">
<item name="android:textAppearance">#style/TextAppearance.AppCompat.Medium</item>
</style>
You just need to extend TextAppearance.AppCompat style overriding necessary values:
<style name="Base_AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textAppearance">#style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textColorHint">?android:textColorHint</item>
<item name="android:textColorHighlight">?android:textColorHighlight</item>
<item name="android:textColorLink">?android:textColorLink</item>
<item name="android:textSize">#dimen/abc_text_size_body_1_material</item>
<item name="textColor">?textColorPrimary</item>
<item name="textColorHighlight">?textColorHighlight</item>
<item name="textColorHint">?textColorHint</item>
<item name="textColorLink">?textColorLink</item>
<item name="textSize">16sp</item>
<item name="textStyle">normal</item>
</style>
If you want to set this style for all your TextView's in your app, you can do something like this:
<resources>
<style name="YourTheme" parent="android:YourParentThTheme">
<item name="android:textViewStyle">#style/GlobalTextViewStyle </item>
</style>
<style name="GlobalTextViewStyle" parent="android:Widget.TextView">
<item name="android:textColor">#FF000</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
<style name="normal_text_white" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#color/white_color</item>
<item name="android:textSize">#dimen/small_text_size</item>
<item name="android:textColorHint">#color/hint_color</item>
</style>
We can try this as well for AppCompat widget.
<style name="TitleStyle" parent="TextAppearance.AppCompat">
<item name="android:gravity">center_horizontal</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textSize">26sp</item>
</style>
Does anyone have an idea how to add the style "MarginButton" to the style "bluebutton" or "OrangeButton"? The reason I'm doing this is to prevent double code, is this the correct way to do or are there better ways to solve this?
<style name="OrangeButton" parent="android:Widget.Button">
<item name="android:textColor">#000</item>
<item name="android:background">#drawable/roundedbutton_orange</item>
</style>
<style name="BlueButton" parent="android:Widget.Button">
<item name="android:textColor">#FFF</item>
<item name="android:background">#drawable/roundedbutton_blue</item>
</style>
<style name="MarginButton" parent="android:Widget.Button">
<item name="android:layout_marginTop">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:layout_marginLeft">3dp</item>
<item name="android:layout_marginRight">3dp</item>
</style>
Thnx,
Joris
Update
Set your orange button parent to #style/MarginButton. I've just tried this and it's working,
<style name="orangeButton" parent="#style/MarginButton">
<item name="android:textColor">#000</item>
<item name="android:background">#drawable/roundedbutton_orange</item>
</style>
<style name="MarginButton" parent="#android:style/Widget.Button">
<item name="android:layout_marginTop">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:layout_marginLeft">3dp</item>
<item name="android:layout_marginRight">3dp</item>
</style>
I think that you can obtain it by doing:
Buttons.xml ->
<style name="OrangeButton" parent="MarginButton">
<item name="android:textColor">#000</item>
<item name="android:background">#drawable/roundedbutton_orange</item>
</style>
<style name="BlueButton" parent="MarginButton">
<item name="android:textColor">#FFF</item>
<item name="android:background">#drawable/roundedbutton_blue</item>
</style>
MarginButton.xml ->
<style name="MarginButton" parent="android:Widget.Button">
<item name="android:layout_marginTop">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:layout_marginLeft">3dp</item>
<item name="android:layout_marginRight">3dp</item>
</style>
If you guys want to use borderless button like me or use two style. Try it.
View ->
<com.google.android.material.button.MaterialButton
android:id="#+id/btnCreateNewAcc"
android:text="#string/or_create_a_new_account"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4"
style="#style/textButtonStyle"
/>
Style ->
<style name="textButtonStyle" parent="android:Widget.Material.Button.Borderless">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:insetTop">0dp</item>
<item name="android:insetBottom">0dp</item>
<item name="android:minWidth">0dp</item>
<item name="android:minHeight">0dp</item>
<item name="android:padding">0dp</item>
<item name="android:fontFamily">#font/inter</item>
<item name="android:textAllCaps">false</item>
<item name="android:textColor">#color/grey</item>
<item name="android:textFontWeight">400</item>
<item name="android:textSize">15sp</item>
<item name="android:background">#android:color/transparent</item>
</style>
You can do it changing the parent attribute. For example:
<style name="BlueButton" parent="MarginButton">
<item name="android:textColor">#FFF</item>
<item name="android:background">#drawable/roundedbutton_blue</item>
</style>
I need to 'hide' the textSize parameter in BigButton style, inherited from Button. How to do so?
<style name="Button">
<item name="android:background">#color/button_background</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:padding">5dp</item>
<item name="android:textSize">#dimen/button_text_size</item>
</style>
<style name="BigButton" parent="#style/Button">
<item name="android:textSize"></item>
</style>
Try
<style name="BigButton" parent="#style/Button">
<item name="android:textSize">#null</item>
</style>