I have make clickable effect on other color buttons But how to generate clickable effect for a white button
<Button
android:id="#+id/featured_listing_button_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-7dp"
android:background="#drawable/botton_account_middle_white"
android:text="Featured Listing" />
What i have tried :: I have made the button White, some other properties
But clickable effect is not present now !
botton_account_middle_white.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke
android:width="3px"
android:color="#000000" />
<corners android:radius="3dp" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
</shape>
How to give clickable effect for the button ! ... White button
You should use selector for Highlighting a Button.
button_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_selected="false"
android:state_pressed="false"
android:color="#color/normal" />
<item android:state_pressed="true"
android:color="#color/pressed" />
<item android:state_selected="true"
android:state_pressed="false"
android:color="#color/pressed" />
</selector>
Use it like
<Button
android:id="#+id/featured_listing_button_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-7dp"
android:background="#drawable/button_selector"
android:text="Featured Listing" />
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true"
android:drawable="#drawable/bgalt" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="#drawable/bgalt" />
<item android:drawable="#drawable/bgnorm" />
</selector>
<Button
android:id="#+id/mybutton"
android:background="#drawable/selector" />
Related
I am trying to color my EditText border as blue when it is having focus. I tried all possible ways as suggested in many answers in Stack Overflow but it doesn't work. It is only changing color of cursor and not of whole border when focused. Below is what I tried, let me know if I am doing incorrectly
That grey border to blue color
styles.xml
<!--Edit Text-->
<style name="EditTextTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">#FFFFFF</item>
<item name="colorControlActivated">#FF1792E5</item>
<item name="colorControlHighlight">#FF1792E5</item>
</style>
edit_text_border.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
<stroke
android:width="1dp"
android:color="#FF1792E5"
/>
</shape>
</item>
</selector>
XML
<EditText
android:id="#+id/edtName"
android:background="#drawable/edit_text_border"
android:inputType="text|textCapWords"
android:maxLength="40"
android:textColor="#color/black"
android:singleLine="true" />
Manifest:
<activity
android:name=".ui.activity.MyActivity"
android:theme="#style/EditTextTheme"
android:screenOrientation="portrait" />
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="#android:drawable/edittext_pressed"
/> <!-- pressed -->
<item
android:state_focused="true"
android:drawable="#drawable/edittext_focused_blue"
/> <!-- focused -->
<item
android:drawable="#android:drawable/edittext_normal"
/> <!-- default -->
</selector>
try this
Try this create a folder in res/drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:color="#color/block" android:width="5dp"/>
<solid android:color="#ffffff"/>
</shape>
XML:
android:background="#drawable/yourborder"
Here is output.
Another Way:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/twitter_im_edittext_normal" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/twitter_im_edittext_normal" />
<item android:state_pressed="true" android:drawable="#drawable/twitter_im_edittext_normal" />
<item android:state_enabled="true" android:state_focused="true" android:drawable="#drawable/twitter_im_edittext_focused" />
<item android:state_enabled="true" android:drawable="#drawable/twitter_im_edittext_normal" />
<item android:state_focused="true" android:drawable="#drawable/twitter_im_edittext_focused" />
<item android:drawable="#drawable/twitter_im_edittext_normal" />
</selector>
I hop this may help you.
try this create a edittext_focused_blue in res/drawable folder like this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
<stroke android:width="1dp" android:color="#ff00" />
<corners android:radius="5dp" />
</shape>
this create a edittext_normal in res/drawable folder like this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
</shape>
try this create a edittext_bg in res/drawable folder like this
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_focused="true"
android:drawable="#drawable/edittext_focused_blue"
/> <!-- focused -->
<item android:state_focused="false"
android:drawable="#android:drawable/edittext_normal"
/> <!-- default -->
</selector>
than apply to your editext using android:background="#drawable/edittext_bg" like this
<EditText
android:id="#+id/edtName"
android:background="#drawable/edittext_bg"
android:inputType="text|textCapWords"
android:maxLength="40"
android:textColor="#color/black"
android:singleLine="true" />
Please try below code to achieve your design:
Drawable Code:
et_border1.xml Drawable for unselected or unfocused edittext.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
<stroke
android:width="1dp"
android:color="#ffffff" />
</shape>
</item>
</selector>
et_border2.xml Drawable for selected or focused edittext.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
<stroke
android:width="1dp"
android:color="#FF1792E5" />
</shape>
</item>
</selector>
edit_text_border drawable to show selected or unselected edittext
<?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/et_border2" />
<item android:state_focused="true" android:drawable="#drawable/et_border2" />
<item android:drawable="#drawable/et_border1" />
</selector>
In 'layout file'
<EditText
android:id="#+id/edtName"
android:inputType="text|textCapWords"
android:maxLength="40"
android:textColor="#android:color/black"
android:singleLine="true"
android:layout_height="40dp"
android:background="#drawable/edit_text_border"
android:layout_width="match_parent"/>
Add or remove color according to requirement
I hope it work for you.
I have tested below code and it works very well.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/ediittext_selector"
android:hint="Demo"
/>
ediittext_selector.xml
<?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/edit_text_border_selected" />
<item android:state_focused="true" android:drawable="#drawable/edit_text_border_selected" />
<item android:drawable="#drawable/edit_text_border" />
</selector>
edit_text_border_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#737373" />
<stroke
android:color="#FF4081"
android:width="1dp" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
edit_text_border.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#737373" />
<stroke
android:color="#F78C1F"
android:width="1dp" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
I added switch, I wanted to change its color, so i added following in drawables.
Thumb.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="#color/black" />
<item android:state_pressed="true" android:drawable="#color/tabAccessoryButtonSelected" />
<item android:state_checked="true" android:drawable="#color/tabAccessoryButtonSelected" />
</selector>
Track.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="#color/tabAccessoryButtonSelected" />
</selector>
Layout.xml
<Switch
android:layout_width="200dp"
android:layout_height="200dp"
android:id="#+id/switch1"
android:layout_centerHorizontal="true"
android:paddingTop="50dp"
android:text="#string/notification_settings"
android:textColor="#color/white"
android:thumb="#drawable/thumb"
android:track="#drawable/track"
/>
As soon as i added this, switch has stopped displaying in the layout, the text is still there, but the Switch tool is not there.
If i remove Thumb.xml and Track.xml it starts displaying switch.
Kindly guide me what i am doing wrong here.
Thanks
I have modify it now try my solution below.
Layout.xml
<Switch
android:layout_width="200dp"
android:layout_height="200dp"
android:id="#+id/switch1"
android:layout_centerHorizontal="true"
android:paddingTop="50dp"
android:text="#string/notification_settings"
android:textColor="#color/white"
android:thumb="#drawable/thumb"
android:track="#drawable/track"
/>
track.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="#drawable/color_thumb" />
<item android:drawable="#drawable/gray_track" />
</selector>
thumb.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="#drawable/gray_track" />
<item android:state_pressed="true" android:drawable="#drawable/color_thumb" />
<item android:state_checked="true" android:drawable="#drawable/color_thumb" />
<item android:drawable="#drawable/gray_track" />
</selector>
color_thumb.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:height="40dp" />
<gradient android:height="40dp" android:startColor="#color/tabAccessoryButtonSelected"" android:endColor="#color/tabAccessoryButtonSelected""/>
</shape>
gray_track.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:height="40dp" />
<gradient android:height="40dp" android:startColor="#color/tabAccessoryButtonSelected" android:endColor="#color/tabAccessoryButtonSelected"/>
</shape>
I know this is an old question but I had the same problem today and the issue seemed to be that the thumb drawable needs a fixed size. The track size seems to adjust itself to the size of the thumb so a thumb with no indicated size won't display and because of this the track won't display either.
If you add an actual xml drawable as a thumb and not just a color you can add a size element to it:
switch_thumb.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/colorSwitchThumb" />
<corners android:radius="#dimen/switch_corner_radius"/>
<size android:height="10dp" android:width="10dp"/>
</shape>
i want to do for user interface which will look like tiles in windows 8. I have something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:layout_weight="1" >
<Button
android:id="#+id/button"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/exit"/>
<Button
android:id="#+id/button2"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
and the second button when is pressed is change a little bit. It is a little bit darker. How do the same for my button where is image background?
You need to set different drawables for each pressed state.
For example, if the normal state image is normal.png and pressed is pressed.png, disabled is disabled.png, focused is focused.png, disabled and focused is disabled_focused.png (doesn't have to be an image - it can be a shape, or whatever):
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_window_focused="false"
android:state_enabled="true"
android:drawable="#drawable/normal" />
<item
android:state_window_focused="false"
android:state_enabled="false"
android:drawable="#drawable/disabled" />
<item
android:state_pressed="true"
android:drawable="#drawable/pressed" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="#drawable/focused" />
<item
android:state_enabled="true"
android:drawable="#drawable/normal" />
<item
android:state_focused="true"
android:drawable="#drawable/disabled_focused" />
<item
android:drawable="#drawable/disabled" />
</selector>
and if the file name the selector is in is called tile.xml, you can now use android:background="#drawable/tile".
do you want to change the button background when it is clicked???
if that is your intention (im sorry it was a bit unclear from the question) you can add a selector as the button background and customise the button as you wish.
add a new xml file custom_button.xml to your drawable and set it as the background of the button : android:background="#drawable/custom_button"
you can change the colors start and end for the different button modes as you like
this is an example of a custom button xml:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="#color/yellow1"
android:endColor="#color/yellow2"
android:angle="270" />
<stroke
android:width="3dp"
android:color="#color/Transparent" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item android:state_focused="true" >
<shape>
<gradient
android:endColor="#color/orange4"
android:startColor="#color/orange5"
android:angle="270" />
<stroke
android:width="3dp"
android:color="#color/Transparent" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="#color/GreenYellow"
android:startColor="#color/Green"
android:angle="270" />
<stroke
android:width="3dp"
android:color="#color/Transparent" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
I have a ListView where I've implemented a Cards UI-type look to it. If an item in the ListView is in the "selected" or "pressed" state, there is a white border around the item. I would like the entire view to have the blue color, but not sure how to achieve that:
ListView item layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:id="#+id/itemLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="#drawable/bg_cards_ui"
>
<TextView
android:id="#+id/title"
android:layout_alignParentTop="true"
android:paddingBottom="4dip"
/>
<TextView
android:id="#+id/summary"
android:paddingBottom="4dip"
android:layout_below="#id/text"
/>
<TextView
android:id="#+id/siteName"
android:layout_below="#id/summary"
/>
<TextView
android:id="#+id/date"
android:layout_below="#id/summary"
/>
</RelativeLayout>
</FrameLayout>
bg_card_ui.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" android:dither="true">
<corners android:radius="2dp"/>
<solid android:color="#ccc" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle" android:dither="true">
<corners android:radius="2dp" />
<solid android:color="#android:color/white" />
<padding
android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp"
/>
</shape>
</item>
<item>
<selector>
<item android:state_pressed="true" android:drawable="#color/my_blue_color" />
<item android:state_selected="true" android:state_pressed="false" android:drawable="#color/my_blue_color" />
<item android:state_activated="true" android:state_selected="false" android:state_pressed="false" android:drawable="#color/my_blue_color" />
<item android:state_selected="false" android:state_pressed="false" android:drawable="#android:color/transparent" />
</selector>
</item>
</layer-list>
Check this out:ListView - Highlight sub layout of item. I've implemented exactly what I think you're looking to do.
Basically, for what you've got, you need to have the selector reference a background xml file in the "drawable" property of the each item. You would need at least two background xml files, one for normal state and one for pressed which has the color changes you want. Should work after that.
i tried to change the drawable of the scrollbar with a selector (state_pressed, state_focus, ...) but i didn't work.
scrollview
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbarSize="5dp"
android:scrollbarThumbVertical="#drawable/custom_scrollbar" >
selector
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_pressed="true"
android:drawable="#drawable/scrollbar_pressed" />
<item
android:state_focused="true"
android:drawable="#drawable/scrollbar_pressed" />
<item android:drawable="#drawable/scrollbar" />
</selector>
one of the two drawables. the only difference is the color
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#color/grey"
android:endColor="#color/dark_grey"
android:angle="0" />
<stroke
android:width="1dp"
android:color="#color/white"/>
<corners android:radius="6dp" />
</shape>
any other solution for this?