Trying to use LevelListDrawable for my ImageView...But it's not working...
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/icon1"
android:maxLevel="0" />
<item
android:drawable="#drawable/icon2"
android:maxLevel="1" />
<item
android:drawable="#drawable/icon3"
android:maxLevel="2" />
</level-list>
This thing i saved in drawable folder...and named as custom_image.xml...
<ImageView
android:id="#+id/someId"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src = "#drawable/custom_image"/>
But my images don't want change...All the time icon1 is shown....What I do wrong ? Thanks..
Related
I need to separate the stars in a RatingBar, it's possible? Or have I to create my own RatingBar?
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="7"
android:id="#+id/estrellas2"
android:scaleX="1.2"
android:scaleY="1.2"
android:layout_below="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="30dp"/>
Set
android:progressDrawable="#drawable/custom_ratingbar_selector"
property to customize rating bar .
and
Create custom_ratingbar_selector.xml in drawable and paste this code
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#android:id/background"
android:drawable="#drawable/unslected_star_icon" />
<item
android:id="#android:id/secondaryProgress"
android:drawable="#drawable/unslected_star_icon" />
<item
android:id="#android:id/progress"
android:drawable="#drawable/slected_star_icon" />
</layer-list>
Try this code,
android:progressDrawable = "#drawable/rat_star"
android:indeterminateDrawable = "#drawable/rat_star"
#drawable/rat_star :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+android:id/background"
android:drawable="#drawable/starempty" />
<item android:id="#+android:id/secondaryProgress"
android:drawable="#drawable/starempty" />
<item android:id="#+android:id/progress"
android:drawable="#drawable/star" />
</layer-list>
In my custom listview, I have used relativelayout and inside that added 2 textviews vertically.
Background image is set to relativelayout. Now I want to change background image as well as textcolor of textview when listview item is pressed.
How to do this, any one have idea?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/item_bg"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#color/orange"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginTop="10dip"
android:layout_marginLeft="10dip"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="20dip"
android:layout_marginTop="8dip"
android:ellipsize="end"
android:maxLines="3"
android:duplicateParentState="true" <!-- this is a line to use..-->
android:textColor="#color/_textcolor"
android:textSize="14sp" >
</TextView>
item_bg.xml inside res/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/bannerbg_hover"/>
<item android:state_focused="true" android:drawable="#drawable/bannerbg_hover" />
<item android:state_selected="true" android:drawable="#drawable/bannerbg_hover"/>
<item android:drawable="#drawable/bannerbg"/>
</selector>
_textcolor.xml inside res/color/ folder:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="#color/white"/>
<item android:state_focused="true" android:color="#color/white" />
<item android:state_selected="true" android:color="#color/white"/>
<item android:color="#color/dark_blue"/>
</selector>
Concerning the background, you should create a StateList Drawable and set it as the background of your rows.
Ex of a such drawable (could be named background_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="#color/color1" /> <!-- pressed -->
<item android:drawable="#color/color2" /> <!-- default -->
</selector>
And in the layout declaration of your row :
...
android:background="#drawable/background_selector"
...
Use the same way for your text with the Color State List
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
I have ICS app with layout which use a ImageView with drawable list. I try to set imageLevel to it but pic doesn't change.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:maxLevel="0"
android:drawable="#drawable/main_activity_idle" />
<item
android:maxLevel="1"
android:drawable="#drawable/main_activity_upload" />
<item
android:maxLevel="2"
android:drawable="#drawable/main_activity_download" />
</layer-list>
<ImageView
android:id="#+id/main_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="6dp"
android:layout_below="#+id/main_panel_logo"
android:layout_alignParentRight="true"
android:src="#drawable/main__dr_list" />
statusIndicator = (ImageView) findViewById(R.id.main_panel_activity);
statusIndicator.setImageLevel(0);
Do you know why it happens?
You should use level-list instead of layer-list.
I have file lst_custom_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:background="#drawable/list_choose"
android:orientation="horizontal">
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#ff000000"
android:textSize="22dp" />
</RelativeLayout>
And Listview in Main.xml
<ListView
android:id="#+id/lstView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"
android:divider="#drawable/menu_phancach"
android:dividerHeight="2dp"
android:visibility="visible">
</ListView>
I use Selector with Background of Relativelayout with name list_choose.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="#drawable/menu_content" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="#drawable/menu_content_hover" />
<item android:state_pressed="true"
android:drawable="#drawable/menu_content_hover" />
</selector>
it's show me the background of RelativeLayout menu_content_hover when i Press on items listview, but not selected with background menu_content_hover. I want it change background menu_content_hover when user press on items and selected ,change backround menu_content when user scroll list(unselected) or choose another items.I used simpleCursorAdapter. Any Help? Thanks for all your help.
The selector should be like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/background_pressed" />
<item android:state_focused="true"
android:drawable="#drawable/background_focused" />
<item android:state_selected="true"
android:drawable="#drawable/background_selected" />
<item android:drawable="#drawable/background_default"/>
</selector>