I have created a spinner which looks like
My layout file is:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_corners"
android:padding="7dip" >
<Spinner
android:id="#+id/select_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:prompt="#string/selectCity" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="14dp"
android:text="#string/City"
android:textColor="#color/dark_grey"
android:textSize="18dp" />
</RelativeLayout>
What I want is to make the background of the spinner transparent but still show the downward arrow. Is there any way that I can do this?
Create xml file and place it in drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/slim_spinner_pressed" />
<item android:drawable="#drawable/slim_spinner_normal" />
</selector>
.
<Spinner ..... android:background="#drawable/selector_slim_spinner" ..... />
For more Information Check this Change Spinner Style In Android
You should create a slector and give that selector as background to your spinner
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/..." />
<item android:drawable="#drawable/..." />
</selector>
you can use this resource Android Holo Colors Generator to generate android components like Android 4.0
Related
I need to customize the text color or background color of the selector when button is selected, because the color of the text its too similar and the text disappears
This is my code:
<android.support.design.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:text="#string/lbl_forgotten_password"
android:textColor="#color/gray_text_1"
android:textSize="14sp" />
This is how it looks:
You can solve this problem by using selector.
Create a new xml file into the drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="#color/text_color" android:drawable="#drawable/button_bg"/>
<item android:color="#color/text_normal" />
</selector>
After
<android.support.design.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/your_xml_file_name"
android:text="#string/lbl_forgotten_password"
android:textSize="14sp" />
this is my fragment
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="135dp"
android:background="#color/colorTerracota"
android:padding="15dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/statetexas"
android:id="#+id/btnTexas"
android:width="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/stateyucatan"
android:id="#+id/btnYucatan"
android:width="100dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/btnTexas"
android:layout_alignStart="#+id/btnTexas" />
</RelativeLayout>
I wanted this see as it:
Set your buttons' background color in your XML file:
android:background:"#9E9E9E" // Your color
Their background is set by default to be transparent.
Create a background selector as below in drawable folder
drawable - selectablebackground.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/grey_lightest" android:state_pressed="true"/>
<item android:drawable="#color/grey_lightest" android:state_focused="true"/>
<item android:drawable="#android:color/white"/>
</selector>
Replace colors as you like for pressed and normal states. Set this as background to your button
android:background:"#drawable/selectablebackground"
This should work.
I have two buttons in bottom of screen, but how can I style stock buttons to style of my concept:
Here my code layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button
android:id="#+id/button1"
android:layout_height="wrap_content"
android:layout_width="180sp"
android:text="Далее"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_alignTop="#+id/button2"
android:layout_alignParentRight="true">
</Button>
<Button
android:id="#+id/button2"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:text="Пропустить"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
</Button>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Добро пожаловать!"
android:id="#+id/textView"
android:layout_marginTop="29dp"
android:fontFamily="sans-serif-thin"
android:phoneNumber="false"
android:textSize="33sp"
android:textColor="#color/text_color"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="25dp" />
</RelativeLayout>
There is multiple ways to do this when building an android application.
The first and simplest is to set your background to an image. To do this add a image to your drawable folders in the res folder, add the correct size images to each drawable folder to correct display across multiple platforms. Once you have imported your image simply put the following line in the layout xml for your button
android:background = "#drawable/imported_image"
The second is to create an selector android XML file. This will let you set the background image for different states of the buttons. I usually create a file under my res folder in my project called drawable and put the xml file there. The selector file would look something like this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="#drawable/large_button_on" />
<item android:drawable="#drawable/large_button_off" />
</selector>
the code to put in your Layout xml inside your button should be
android:background="#drawable/custom_button"
The final way without using any images is to define a shape android xml file for the button. This will instruct how you want the button to be drawn on screen. This xml should be placed in your project the same way we did with the other.
?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#000000"
android:endColor="#0000ff"
android:angle="270" />
<stroke android:width="1dp" android:color="#ffffff" />
</shape>
again if you use this method put the following in your layout xml for your button
android:background="#drawable/custom_button"
Hope these methods of styling help.
You can create an drawable xml file like this and have a different drawable for the different states of you button
res/drawable/my_button_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/button_focused"
android:state_focused="true" />
<item android:drawable="#drawable/button_default" />
</selector>
Then in your button's declaration add the line:
android:background="#drawable/my_button_drawable" />
Android Developer Buttons
I have a problem with changing button background image.
So i have 2 images (png-24 transparent background).
Images are a simple circle and the same circle but with some outerglow ).
I have the following code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ticketing_row_topup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#layout/pressed_topup_button"
android:orientation="horizontal" >
<TextView
android:id="#+id/topup_name"
android:layout_width="60dp"
android:layout_height="fill_parent"
android:gravity="center_vertical|right"
android:paddingRight="5dip"
android:paddingTop="22dip"
android:text="€"
android:textColor="#color/black"
android:textSize="35sp"
android:textStyle="bold" />
<TextView
android:id="#+id/topup_display_amount"
android:layout_width="90dp"
android:layout_height="match_parent"
android:gravity="center_vertical|left"
android:textSize="65sp"
android:textColor="#0d457f"
android:textStyle="bold" />
</LinearLayout>
And the pressed_topup_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:state_enabled="false">
<item android:state_pressed="true" android:state_enabled="true" android:drawable="#drawable/button_topup_glow" />
<item android:state_focused="true" android:state_enabled="true" android:drawable="#drawable/button_topup" />
<item android:state_enabled="true" android:drawable="#drawable/button_topup" />
</selector>
The LinearLayout is used to populate a GridView in each cell.
When i click the cell the behavior is correct (the glow is displayed) but also a yellow color is display on the corner of the image (where suppose to be transparent). How can i fix that?
Thanks
You need to add
android:listSelector="#android:color/transparent"
to your GridView declaration.
See this:
Android: Disable highlighting in GridView
I am trying to apply a transparent background to my row when it is pressed in my ListView. I create the file list_selector.xml like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/argb80804040" />
</selector>
and in my news_item.xml, I define the back ground as follow:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/list_selector">
<ImageView
android:id = "#+id/img"
android:layout_width="95dip"
android:layout_height="75dip"
android:layout_alignParentLeft = "true"
android:paddingTop="10dip"
android:layout_marginLeft="10dip"
android:paddingBottom="10dip"
android:src="#drawable/no_news_image_small" />
<TextView android:id="#+id/title"
android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"
android:paddingTop="5dip"
android:layout_marginLeft="110dip"
android:textColor="#21B6EF"
android:singleLine="true" />
<TextView android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:layout_marginLeft="110dip"
android:textSize="10sp"
android:id="#+id/description"
android:layout_below="#id/title"
android:paddingBottom="10dip"
android:layout_marginBottom="5dip"
android:textColor="#fff"/>
</RelativeLayout>
However, it displays as solid color instead of ARGB color. My drawable is define as follow:
<resources>
<item type="drawable" name="transparent_orange">#64ff7b00</item>
<item type="drawable" name="argb80804040">#80804040</item>
<item type="drawable" name="argb40000000">#40000000</item>
<item type="drawable" name="argb80408040">#80408040</item>
</resources>
Do I need to do something else to get aplha color working? I am trying on my own device (motorola defy), and i am also using another application that uses the same alpha color and the color appears ok in this application, but in mine, it doesnt.
Many thanks for any response
T
I don't really understand what do you want to achieve but my proposal will be
Define your colors in res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent_orange">#64ff7b00</color>
...
</resources>
Then you can define a drawable to be used as a background like this in res/drawable/test.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/transparent_orange" />
</shape>
Finally, you can use the resulting drawable as an attribute of the target container with
android:background="#drawable/blue_linear_gradient"