I'd like to use my own image as handler's image.
How can i change the default handler image to onther image?
Thanks,
Eyal.
You can use an ImageView with src pointing to your image as the handle:
<SlidingDrawer
android:id="#+id/drawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:handle="#+id/handle"
android:content="#+id/content">
<ImageView
android:id="#id/handle"
android:src="#drawable/my_image"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
....
</SlidingDrawer>
You will probably want to convert that image to a 9patch so it can be stretched to fill the height of the window.
you should use a selector for the slider button so that you can have different images for different states(focussed,non focussed etc...)
<?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="false" android:drawable="#drawable/focused" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="#drawable/focusedpressed" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="#drawable/pressed" />
<item android:drawable="#drawable/defaultbutton" />
</selector>
adding background image to the SlidingDrawer's button.
Related
I am creating a simple button as follows :
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edSearch"
android:id="#+id/btnSearch"
android:layout_marginTop="30dp"
android:drawableTop="#drawable/ic_action_search"
android:textSize="16sp"
android:text="Search"
android:background="#color/md_green_500"
android:textColor="#fff"
/>
Now, when i try add any image in background like :android:background="#drawable/img123" then button raise effect does not work. is there any way i can achieve raise effect with background image ?
You can create a selector drawable for this. You need to provide 3 different images for this so that the button can toggle those images as per the state.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false"
android:state_pressed="false"
android:drawable="#drawable/image_normal" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="#drawable/image_pressed" />
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="#drawable/image_focused" />
</selector>
Also inspite of that you can use ImageButton which will keep your image in center of button and the effects will be default as per operating system.
I am using selector for imageView to change image on press event.
but it is not changing image when I press on it.
Here is selector,
<?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/fed_1" />
<item
android:drawable="#drawable/fed" />
</selector>
And this is my imageview,
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:src="#drawable/sel_fed" />
Also tried using background for image view but it's not working.
you should add android:clickable="true". Your imageView will be like this
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:clickable="true"
android:src="#drawable/sel_fed" />
change your src to background and add android:clickable="true" to your ImageView
You can try this selector
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/fed_1" android:state_selected="true"></item>
<item android:drawable="#drawable/fed_1" android:state_pressed="true"></item>
<item android:drawable="#drawable/fed"></item>
</selector>
Change src to background in your image view.
android:background="#drawable/sel_fed"
This is my problem: I have an ImageView and I assign a selector to it, so the image have to change when I touch it. The problem is that the image doesn't change.
The selector has a different name than the image sources, so that is not a problem. When I touch the image, the app does an http call, so I think that there is the problem, but I don't know how to solve this.
Selector xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/pat_login_button_pressed"
android:state_selected="true" />
<item android:drawable="#drawable/pat_login_button_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/pat_login_button"
android:state_selected="false" />
</selector>
ImageView xml:
<ImageView
android:id="#+id/login_button"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:src="#drawable/pat_login_button_selector" />
i want to make image button, so when it pressed i will replase the not-pressed image to pressed image of the button, and then go to other activity. i have two different images in drawable.
i have two xml files:
first one- load the main activity: background and image button
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/black"
android:orientation="vertical" >
<ImageButton
android:id="#+id/b1_l"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/s1"
android:scaleType="centerCrop"
android:background="#color/trans"
android:src="#drawable/b1_l" />
</RelativeLayout>
second one:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:drawable="#drawable/image_not_pressed" />
<item android:state_pressed="true"
android:drawable="#drawable/image_pressed"" />
</selector>
what is the code that i need to write in addition to my xml?
or can i pass the xml and write it only as code...?
thanks!
you need to usually have drawable for pressed and default(unpressed) state. You can have the xml file like this(below) for that. You need to put this xml file in the drawable folder and then use as src for ImageButton or background source in case of Button.
Lets name it is mybutton.xml
<?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/your image name" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="#drawable/your image name" />
<item android:drawable="#drawable/your image name" />
</selector>
You layout file for main activity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/black"
android:orientation="vertical" >
<ImageButton
android:id="#+id/b1_l"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/s1"
android:scaleType="centerCrop"
android:background="#color/trans"
android:src="#drawable/mybutton" />
</RelativeLayout>
You migth want do check out android developer guide on this
http://developer.android.com/guide/topics/ui/controls/button.html
Hi I have created a relative layout. and align the imageview to the right of relativelayout. I set the background of relativelayout using selector. if i select thye relativelayout its color wil be green otherwise its color will be white. Now I want to set the image depending on the selection of scrollview. If scrollview is selected then i want to show imge1 if not then i want to show image2. How can I achieve this?
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow_right"
android:layout_alignParentRight="true" />
</RelativeLayout>
selector.xml
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="#drawable/grbk" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="#drawable/grbk" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="#drawable/grbk" />
<item
android:drawable="#drawable/whbk" />
</selector>
Thanks
Sunil
In the same way as for background. You should add android:duplicateParentState="true"
<ImageView
android:duplicateParentState="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow_selector"
android:layout_alignParentRight="true" />
first set the color to all the list list view item and then put the selector in the list view ..i gess u know how to set the selector in list view
We can create another selector for imageview and pass that selector as background to imageview.
imageselector.xml
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="#drawable/arow_selected" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="#drawable/arow_selected" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="#drawable/arow_selected" />
<item
android:drawable="#drawable/arow_unselect" />
</selector>
main.xml
<ImageView
android:id="#+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/imageselector"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dip"/>
</RelativeLayout>
Here is my suggestion..
once i set the background to the imageview, then when i want to change the transparent, i can do nothing...after check some website, i found i need to set the imageview's resourse instead of background...