Set background color of MaterialSpinner - java

I am using this (https://github.com/ganfra/MaterialSpinner) for my spinner in my project. The problem is i did't find any way to change the spinner's background. I've try to use android:background="#fff", then try to use android:theme="#style/myspinnertheme" which is changeing the background but still did't work. I don't know another way i can try :D
<fr.ganfra.materialspinner.MaterialSpinner
android:id="#+id/spCategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="#fff"
app:ms_baseColor="#color/colorAccent"
app:ms_floatingLabelText="Kategori"
app:ms_enableErrorLabel="true"
app:ms_hint="Pilih Kategori : "/>
This is my project screen shoot :
Look at the spinner at bottom, i want to change the background color to white, what shall i do?

It happens because material spinner set background resources in constructor and changes your background. So just reset background resources with your color. Example:
Create background.xml in drawable( colors for default, pressed and selected spinner's state)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#android:color/darker_gray"/>
</shape>
</item>
<item android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="#android:color/darker_gray"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/black"/>
</shape>
</item>
And set it
MaterialSpinner spinner = (MaterialSpinner) findViewById(R.id.spCategory);
spinner.setBackgroundResource(R.drawable.background);

You can use custom:ms_baseColor="#color/green"

Related

Change button style to custom xml file by overriding android studio default button style

I want custom button design to my button but android stdio has default button style which has purple color and I am not able to remove that.
My xml code of design:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#color/teal_200"
android:endColor="#color/purple_200"
android:angle="270"/>
<corners android:radius="30dp"/>
</shape>
Default button style is:
Default Button Image
Design I want to my button:
My Button Design
you can be added
android:centerColor
like this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#00e0d1"
android:centerColor="#2fc1ea"
android:endColor="#C791F8"
android:angle="270"/>
<corners android:radius="30dp"/>
</shape>
after if you can add your button background
android:background
like this
<Button
android:layout_width="100dp"
android:layout_height="50dp"
android:background="#drawable/custom_bg"/>

How set background color for buttons using xml files?

i create this xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#color/light_blue"
android:centerColor="#color/dark_blue"
android:endColor="#color/light_purple"
>
</gradient>
<corners
android:radius="30dp">
</corners>
</shape>
</item>
</selector>
and i trying to set this file to my button background.but problem is background dose not accept colors of xml file.it is use backgroundTint colors and not the colors i set above.
THIS IS MY ACTIVITY_XML
<Button
android:id="#+id/temp_l"
android:layout_width="250dp"
android:layout_height="33dp"
android:background="#drawable/temp_shape"
app:layout_constraintBottom_toTopOf="#+id/scrollView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.143" />
i searched in youtube and saw that eveyone did what i did but they get result and im not.
sorry about my english.its not very well.
I guess you are using android:backgroundTint="#null" with android namespace, but you need to set app:backgroundTint="#null" with app namespace instead
Side note:
You should wrap the xml drawable into a layer-list as long as you have no need to the selector, so you might change it to:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:centerColor="#055D93"
android:endColor="#color/light_purple"
android:startColor="#color/light_blue" />
<corners android:radius="30dp">
</corners>
</shape>
</item>
</layer-list>
Preview

Android layerlist is not working in different mobiles

I want to create a drawable file like the below screenshot.
My drawable xml file:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="0px"
android:left="0px"
android:right="0px"
android:bottom="0px">
<shape android:shape="rectangle">
<corners android:radius="#dimen/_6sdp" />
<solid android:color="#color/activeslots"/>
</shape>
</item>
<item
android:top="#dimen/_14sdp"
android:left="#dimen/_12sdp"
android:right="#dimen/_58sdp"
android:bottom="#dimen/_14sdp">
<shape android:shape="oval">
<solid android:color="#color/white"/>
<size android:height="#dimen/_20sdp"
android:width="#dimen/_20sdp"/>
</shape>
</item>
</layer-list>
I created rectangle and oval inside the layer_list. But the issue is it is not working in different mobiles, also the white circle inside the drawable is becomes big after setting height and width.

how do you make buttons flash or blink different colours in android eclipse?

I am creating a tic tac toe program. I can get the buttons to display an X or 0 but I can't get them to display different colours. How would I do this?
Use a selector to change button color when clicked.
/res/drawable/btn_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid android:color="#ffaa66"/>
</shape>
</item>
<item>
<shape>
<solid android:color="#ffdd99"/>
</shape>
</item>
</selector>
And now apply this xml as android:background to the button.

Changing Spinner Highlight AND line color

This XML below results in my Spinner having an orange line across the bottom and an orange rectangle on the right-hand side. I have two questions:
How can I make it so that the orange rectangle on the right-hand side is an orange triangle, like the default one associated with Theme.Dialog?
Now that I changed the look of the Spinner, when I click on it it no longer gets highlighted. I want to make it look the way I want AND highlight to a lighter color of orange when I press on it.
Do I have to accomplish both things in the same XML file? I've already got the drawable below set to the background of my spinner, so I can't declare the background twice right?
Any ideas? Thanks in advance!
My Drawable Custom Spinner Layout:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape >
<solid android:color="#color/base_orange" />
</shape>
</item>
<!-- main color -->
<item android:bottom="1.0dp"
android:left="0.0dp"
android:right="10.0dp">
<shape >
<solid android:color="#color/white" />
</shape>
</item>
<item android:bottom="25.0dp">
<shape >
<solid android:color="#color/base_orange" />
</shape>
</item>
</layer-list>
You could refer to this and get the spinner drawables according to your wish.
Hope that helps

Categories