Styles and different Android platforms - android-layout

Given the following style in file: res/values/styles.xml
<style name="GiftCardFragment.TitleLLLabelTV">
<item name="android:paddingStart">5dp</item>
<item name="android:paddingLeft">5dp</item>
</style>
android:paddingStart is only valid in Android platform 17 and above, so then I would create a new styles.xml file in "res/values-v17/styles.xml".
But the question is: Do I have to repeat the whole style, or could I just add the styles I want to add extra (alternatively override) for a given platform and above in "res/values-v17/styles.xml"? Like:
<style name="GiftCardFragment.TitleLLLabelTV">
<item name="android:paddingStart">5dp</item>
</style>
And then Android would merge then at runtime. Am I correct? Any pointing in right direction appreciated, I couldnt find documentation really covering this case.

Related

MaterialButton style shapeAppearance not working

I'm struggling to set the right style for my button in the project. I don't know why shapeAppearance not working. Even if I use only cornerSize it's not working.
I have a base style for a button:
<style name="SnButton" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="shapeAppearance">#style/MyShapeAppearance</item>
<item name="backgroundTint">#null</item>
</style>
This is my shape appearance for a button:
<style name="MyShapeAppearance" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">2dp</item>
</style>
This is my base theme: Theme.MaterialComponents.Light.NoActionBar.Bridge
What should I do to force shapeAppearance work in my case? Or at least cornerSize?
I figured out why style was not working!
The problem was in the way I set the color for the button. I've used android:background, but backgroundTint must be used.

Android Studio design preview doesn't show activity title or icons in toolbar when using basic activity template

I've been searching for a while now for a way to fix this and haven't even found a similar issue. I'm using the basic activity template from Android Studio which uses a toolbar instead of an action bar. When I run the app, everything looks as it should, activities have their title, up arrow and icons. But the design preview only shows an empty toolbar. I haven't messed with anything that came predefined in the template, so styles are the following:
<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="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
In the manifest, style/AppTheme is automatically applied to the application, and style/AppTheme.NoActionBar to each activity that was created using the basic activity template. In the design preview, which is using by default the AppTheme.NoActionBar theme, I see an empty toolbar like this:
If I change the theme to AppTheme, the title and up arrow shows, but there is then an empty toolbar below:
How do I make the toolbar show only once and with title and icons in the design preview?

Change android editText highlight color

Does anyone know how can I change this green color that appears in my editText ?
I would like to do it from the layout XML if it is possible
just below the editText image.
Any help is appreciated.
I could resolve it adding: android:backgroundTint="#color/color_you_wat" to the EditText in the layout file
Programmatically:
editText.getBackground().mutate().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_ATOP);
Using theme:
<style name="AppThem" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- change values below to make same eefect for all EditTexts ->
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#color/accent</item>
<item name="colorControlHighlight">#color/accent</item>
</style>
<!-- also you can create different styles with values above for many different views ->
Edit:
You can always use in xml file:
"app:backgroundTint="#color/myColor" in xml.
Don't use android:. Otherwise you would lose backward compability with Android 4.4 and older.
Hope it help

A Style Resource related 'Widget' error in android application --

I'll describe my problem first. I'm trying an android app. Doing it using Xamarin Android. I've done the parts I need, the necessary code; but Compiling my code gives me some errors in the Styles.xml file.
The error is like this::
Error APT0000: Error retrieving parent for item: No resource found that matches the given name 'Widget'. (APT0000) (TestALLApp)
Basically 5 errors, the above error repeating itself 5 times for the 5 style definitions in the Stylex xml file.
This is my Styles.xml file::
<resources>
<style name="Widget.SampleContentContainer"> <---- error shown here
<item name="android:paddingTop">#dimen/vertical_page_margin</item>
<item name="android:paddingBottom">#dimen/vertical_page_margin</item>
<item name="android:paddingLeft">#dimen/horizontal_page_margin</item>
<item name="android:paddingRight">#dimen/horizontal_page_margin</item>
</style>
<style name="Widget.SampleDashboard.Grid" parent="Widget">
<item name="android:stretchMode">columnWidth</item>
<item name="android:columnWidth">200dp</item>
<item name="android:numColumns">auto_fit</item>
<item name="android:drawSelectorOnTop">true</item>
<item name="android:horizontalSpacing">#dimen/margin_medium</item>
<item name="android:verticalSpacing">#dimen/margin_medium</item>
</style>
<style name="Widget.SampleDashboard.Item" parent="Widget">
<item name="android:background">#drawable/sample_dashboard_item_background</item>
<item name="android:paddingTop">#dimen/margin_small</item>
<item name="android:paddingLeft">#dimen/margin_medium</item>
<item name="android:paddingRight">#dimen/margin_medium</item>
<item name="android:paddingBottom">#dimen/margin_medium</item>
</style>
<style name="Widget.SampleDashboard.Item.Title" parent="Widget">
<item name="android:layout_marginBottom">#dimen/margin_tiny</item>
<item name="android:textAppearance">?android:textAppearanceLarge</item>
<item name="android:textColor">#09c</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">24sp</item>
</style>
<style name="Widget.SampleDashboard.Item.Description" parent="Widget">
<item name="android:textAppearance">?android:textAppearanceSmall</item>
<item name="android:fontFamily">sans-serif-light</item>
</style>
You can see the line on which the error is shown. Among the references I added to my project were
Xamarin.Android.Support.v4
Xamarin.Android.Support.v7.RecyclerView
That's All. As per the error message I suppose, 'Error retrieving parent for item' should mean it cannot find/locate a parent called 'Widget'. I did search for any nuget package like Xamarin Widget, anything of that name or similar name doesn't exist. At least my nuget package search cannot list/find anything like that. Or is it something to do with a style element definition called 'Widget' too in that xml file? So what is the actual correct thing to be done please, if someone could show me, it'd help me very much. Is it just a missing nuget package? If so what is the proper correct name of it please['widget'].
Please help me a little on this matter.
Thanks so much.
As I have used it before, the parent attribute's value is the parent style that you will start with, then override the various properties within there. For me, I have always used parent attribute values such as "#android:style/Theme.Holo.Light", .Dark, and so on. Unless there is a theme named Widget, I don't see this working.
PS. Obviously, the holo styles were first introduced in android 3.x/4.x, so I doubt that they would work in previous versions of android without including some other stuff to make them work. You used the Xamarin.Forms tag for the question, so this won't be a big deal since XF only runs on android 4 and later.

Setting a spinner divider for one specific spinner

I've recently been looking into customizing the divider colour between items in a Spinner's drop down list, and I found the way to do it for all spinners at once via the application theme. For example:
<style name="custom_divider">
<item name="android:divider">#FFFFFF</item>
<item name="android:dividerHeight">5dp</item>
</style>
<style name="holo_light_dark_action_bar_custom_dropdown" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:dropDownListViewStyle">#style/custom_divider</item>
</style>
What I want to do is style the dividers for one specific spinner (in this case, the spinner in the action bar), rather than all spinners. I haven't seen any solutions for that, so I'm hoping it's something obvious and that I just missed it. :)

Resources