RatingBar Theme working in Marshmallow but not in Lollipop - android

I am trying to style my RatingBar with the following code:
<style name="RatingBarfeed" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/duskYellow</item>
</style>
And in layout.xml I am using the following code:
<android.support.v7.widget.AppCompatRatingBar
android:theme="#style/RatingBarfeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:id="#+id/ratingBar"
android:paddingBottom="0.45dp"
app:layout_constraintTop_toTopOf="#+id/rating"
app:layout_constraintLeft_toRightOf="#+id/rating"
app:layout_constraintBottom_toBottomOf="#+id/rating"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:background="#color/orange"
android:rating="3.5"
android:stepSize="0.5"/>
Its working fine in Marshmallow (check the screenshot)
But in Lollipop Theme is not working (check the screenshot)
Please Help...!!!!

After much struggle I got my answer:
it should be style="#style/RatingBarfeed" instead of android:theme+"#style/RatingBarfeed"
For styling star fill, empty and partial color
android:progressTint="#F9BB28"
android:progressBackgroundTint="#color/white"
android:secondaryProgressTint="#color/white"
Final code should be like
<android.support.v7.widget.AppCompatRatingBar
android:layout_width="wrap_content"
android:layout_height="18dp"
style="#style/RatingBarfeed"
android:id="#+id/ratingBar"
android:gravity="center"
android:progressTint="#F9BB28"
android:progressBackgroundTint="#color/white"
android:secondaryProgressTint="#color/white"
app:layout_constraintTop_toTopOf="#+id/rating"
app:layout_constraintLeft_toRightOf="#+id/rating"
app:layout_constraintBottom_toBottomOf="#+id/rating"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:background="#color/orange"
android:rating="3.5"
android:stepSize="0.1"/>
Style should be:
<style name="RatingBarfeed" parent="android:style/Widget.Material.RatingBar.Small">
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/duskYellow</item>
</style>

Related

How to use default android themes?

Hy
I created an android project, and I saw thet, tehe are two themes.xml file. In emulator, when I switch day and night mode, my application color schema is changes too.
I thought it is greate, because with thease themes it will be easy to create a day/night app, but I don't know how it works.
How can I define a new color item inside themes, and use this schema for layout background?
For example: There is an item in both themes
<item name="colorPrimary">#303F9F</item>
And I would like to create a new item for both themes.xml, and use it to set up fragment background color, but the intellisense doesn't find this element directly.
<item name="backgroundColor">#303F9F</item>
You can change color easily from where you define your theme in 'styles.xml'.
<resources>
<!-- 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="AppThemeDark" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorSecondary</item>
<item name="colorPrimaryDark">#color/colorSecondaryDark</item>
<item name="colorAccent">#color/colorSecondaryAccent</item>
</style>
I have two themes in my app so if i change the color or anything in my theme i will define that color in my selected theme for example:
i want to change the background color of 'AppThemeDark' i just define the color like this
<item name="background">#color/"#fff67"</item>
copy this line in your first screen
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
Ok In constraintlayout background tag is not worked so I will fix this problem with the use of View.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#AAA">
<View
android:id="#+id/background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#FFF"
app:layout_constraintBottom_toBottomOf="#+id/textView3"
app:layout_constraintEnd_toEndOf="#+id/textView1"
app:layout_constraintStart_toStartOf="#+id/textView1"
app:layout_constraintTop_toTopOf="#+id/textView1" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="#+id/textView1"
app:layout_constraintStart_toStartOf="#+id/textView1"
app:layout_constraintTop_toBottomOf="#+id/textView1"
tools:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="#+id/textView1"
app:layout_constraintStart_toStartOf="#+id/textView1"
app:layout_constraintTop_toBottomOf="#+id/textView2"
tools:text="TextView" />
</android.support.constraint.ConstraintLayout>

Android Change TextColor of selected NumberPicker

I have created a NumberPicker in Android Studio but I cannot change the color of the selected item. The only thing I have found in this forum is this way:
<style name="AppTheme.Picker" parent="Theme.AppCompat.Light.NoActionBar" >
<item name="android:textColorPrimary">#android:color/black</item>
</style>
but that changes the text color of all items.
My NumberPicker:
<NumberPicker
android:id="#+id/numberPicker1"
android:layout_width="306px"
android:layout_height="300px"
android:selectionDividerHeight="0dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:descendantFocusability="blocksDescendants"
android:fontFamily="#font/questrial"
android:scaleX="2.5"
android:scaleY="2.5"
android:theme="#style/AppTheme.Picker"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.827"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.513" />
<style name="AppTheme.Picker" >
<item name="android:textSize">50px</item>
</style>
sample
In this case, only want to change the text color of 36.4

Setting spinner popup background color

I can set the background of the popup menu of a spinner using:
<Spinner
android:popupBackground="#color/darkThemeBackgroundColor"/>
But how do I set the background text color of it?
This solution is more simpler, you only need add this code to styles.xml
<style name="spinnerTheme">
<item name="android:background">#color/colorDark</item>
<item name="android:textColor">#android:color/white</item>
<!-- this is for api 19 text color -->
<item name="android:color">#android:color/white</item>
</style>
And this is how use in your layout file
<Spinner
android:id="#+id/spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:padding="8dp"
android:entries="#array/aves"
android:theme="#style/spinnerTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
That is the result:
I hope this solution helps you, greetings.

android special button theme with shape above

I'm trying to create a button that looks like that:
So I have created this style:
<style name="button_main" parent="#android:style/Widget.Button">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FFFFFFFF</item>
<item name="android:shadowColor">#FF000000</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">-1</item>
<item name="android:shadowRadius">0.2</item>
<item name="android:textSize">16dip</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/button_main</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
</style>
and applied this to the button:
<Button
android:id="#+id/btnConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONNECT"
style="#style/button_main"
android:drawableTop="#drawable/ic_connect"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_home" />
but this is my result:
any idea how I can add the green background to the text as well? and how can I add the white tint to the icon?
how can I add the white tint to the icon?
app:drawableTint="#color/white"
Edit:
Create separate TextView inside root layout below to button
Try This:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#color/green">
<Button
android:id="#+id/btnConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_main"
android:drawableTop="#drawable/ic_wifi_24"
app:drawableTint="#color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_margin="#dimen/margin_12dp"
app:layout_constraintTop_toBottomOf="#+id/text_home" />
<TextView
android:id="#+id/tvConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
app:layout_constraintTop_toBottomOf="#id/btnConnect"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="Connect"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Above code will give expected result might be you have to adjust padding n margin lil bit .

Spinner Dropdown selection

I have a spinner as drowdown, when i click on the spinner item i want to show my own selector.
The code i wrote is
<Spinner
android:id="#+id/regions"
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_marginBottom="9dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
style="#style/regionSpinnerTheme"
android:layout_marginTop="9dp" />
<style name="regionSpinnerTheme" parent="#android:Theme.Light">
<item name="android:spinnerStyle">#style/Widget.Spinner</item>
</style>
<style name="Widget.Spinner" parent="android:Widget">
<item name="android:listSelector">#drawable/tw_list_dark</item>
<item name="android:dropDownSelector">#drawable/tw_list_dark</item>
<item name="android:drawSelectorOnTop">false</item>
I m getting a green color in selection .Please Help me.
This is a bug in adroid. One of many many unfixed bugs.
https://code.google.com/p/android/issues/detail?id=24922
And BTW: You should let out the intermediate step regionSpinnerTheme.
Something like:
<Spinner
android:id="#+id/regions"
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_marginBottom="9dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
style="#style/Widget.Spinner.Region"
android:layout_marginTop="9dp" />
<style name="Widget.Spinner.Region" parent="android:Widget">
<item name="android:dropDownSelector">#drawable/tw_list_dark</item>
</style>
But as said, this does not work due to bug.

Categories

Resources