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
Related
Here is the XML code of My MaterialButtonToggleGroup
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="#+id/type_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/welcome_text"
app:selectionRequired="true"
app:singleSelection="true">
<com.google.android.material.button.MaterialButton
android:id="#+id/total_silence_button"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/total_silence"
android:textColor="#color/light_green_700"
android:textStyle="bold"
app:rippleColor="#color/light_green_700"
app:strokeColor="#color/light_green_700" />
<com.google.android.material.button.MaterialButton
android:id="#+id/priority_only_button"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/priority_only"
android:textColor="#color/light_green_700"
android:textStyle="bold"
app:rippleColor="#color/light_green_700"
app:strokeColor="#color/light_green_700" />
<com.google.android.material.button.MaterialButton
android:id="#+id/calls_only_button"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foregroundTint="#color/light_green_700"
android:text="#string/calls_only"
android:textStyle="bold"
app:iconTint="#color/light_green_700"
app:rippleColor="#color/light_green_700" />
</com.google.android.material.button.MaterialButtonToggleGroup>
And the output is .
When I select a button, the background color by default is
My question is how to change the purple(ish) color with the same opacity?
Note:
I couldn't find any attribute to change the color.
The selected background color with a M3 theme is defined by the colorSecondaryContainer attribute.
You can override it using:
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="#+id/type_toggle"
app:materialThemeOverlay="#style/button_overlay"
with:
<style name="button_overlay" >
<item name="colorSecondaryContainer">#ffe6e1e5</item>
</style>
Otherwise you can define a custom style for each Button usign:
<com.google.android.material.button.MaterialButton
android:id="#+id/priority_only_button"
style="#style/App.Material3.Button.OutlinedButton"
with:
<style name="App.Material3.Button.OutlinedButton" parent="Widget.Material3.Button.OutlinedButton">
<item name="backgroundTint">#color/app_m3_text_button_background_color_selector</item>
</style>
where the selector is:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- selected color -->
<item android:color="#color/teal_200" android:alpha="0.12"
android:state_enabled="true" android:state_checked="true"/>
<item android:color="?attr/colorContainer"/>
</selector>
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.
I want to change the color of the active toggle button. But just the change of the rippleColor makes a difference.
I wish to customize the background color of the active button and the text color.
<style name="ToggleButtonGroupStyle" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="rippleColor">#color/colorAccent</item>
</style>
In the following toggleButtonGroup I used this style from above:
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="#+id/priority_btn_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentLeft="true"
app:selectionRequired="true"
app:singleSelection="true"
app:checkedButton="#+id/btn_one"
>
<com.google.android.material.button.MaterialButton
android:id="#+id/btn_one"
style="#style/ToggleButtonGroupStyle"
android:layout_width="#dimen/priority_btn_width"
android:layout_height="wrap_content"
android:shadowColor="#color/project_text"
android:text="0" />
<com.google.android.material.button.MaterialButton
style="#style/ToggleButtonGroupStyle"
android:layout_width="#dimen/priority_btn_width"
android:layout_height="wrap_content"
android:text="!" />
<com.google.android.material.button.MaterialButton
style="#style/ToggleButtonGroupStyle"
android:layout_width="#dimen/priority_btn_width"
android:layout_height="wrap_content"
android:text="!!" />
<com.google.android.material.button.MaterialButton
style="#style/ToggleButtonGroupStyle"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="!!!" />
</com.google.android.material.button.MaterialButtonToggleGroup>
Could anybody give me a hint what the problem here is?
Thanks :)
The background color of the checked buttons is based on the colorPrimary attribute.
You can use:
<com.google.android.material.button.MaterialButton
android:id="#+id/btn_one"
style="?attr/materialButtonOutlinedStyle"
android:theme="#style/ThemeOverlay.Custom.Button"
with:
<style name="ThemeOverlay.Custom.Button" parent="">
<item name="colorPrimary">#color/....</item>
</style>
or you can use a custom style with:
<com.google.android.material.button.MaterialButton
android:id="#+id/btn_one"
style="#style/ToggleButtonGroupStyle"
with:
<style name="ToggleButtonGroupStyle" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="backgroundTint">#color/custom_selector</item>
</style>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/..." android:state_checked="true"/> <!-- selected color -->
<item android:color="#android:color/transparent" android:state_checked="false"/>
</selector>
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 .
I am trying to set default style for edit text view. In this example, I have set default style for editText as well as for textView.
Here is my styles.xml from values folder:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:editTextStyle">#style/AppTheme.EditText</item>
<item name="android:textViewStyle">#style/AppTheme.TextView</item>
</style>
<style name="AppTheme.EditText" parent="android:Widget.EditText">
<item name="android:textColor">#color/red</item>
<item name="android:padding">10dp</item>
</style>
<style name="AppTheme.TextView" parent="android:Widget.TextView">
<item name="android:textColor">#color/red</item>
<item name="android:padding">10dp</item>
</style>
</resources>
As shown in the snapshots below, I have added two editText and two textView in layout.
Here is my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="TextView1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:text="TextView2" />
<EditText
android:id="#+id/editText1"
style="#style/AppTheme.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_marginTop="20dp"
android:ems="10"
android:text="EditText1" >
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_marginTop="20dp"
android:ems="10"
android:text="EditText2" >
</EditText>
</RelativeLayout>
Now the issue is, default style for textView works fine but for editText view it does not reflect the style. If I explicitly set style for editText then it reflects as expected (as done for editText1), but not by default. Text color for editText2 should be red but it's not. Am I missing something?
Hi prashant..just i copied your code in my project. for me its working
do you want like this? or anything else?