I got a stange error (no this won't help...)
I got a seperate layout for the tabbar. tabs_bg.xml is the layout. tab_text_selector.xml for the textColor and colors.xml. (Nameing of the colors might be misleading, but this is for testing)
If I click on the Graphical Layout, I got the error: java.lang.NumberFormatException: For input string: "#color/tab_unselected"
tabs_bg.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabsLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:gravity="center"
android:orientation="vertical"
android:background="#drawable/tabbar_background" >
<TextView android:id="#+id/tabsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="15dip"
android:ellipsize="marquee"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
android:textColor="#drawable/tab_text_selector"/>
</LinearLayout>
tab_text_selector.xml
<?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/tab_unselected" />
<item android:state_focused="true"
android:color="#color/tab_unselected" />
<item android:state_pressed="true"
android:color="#color/tab_selected" />
<item android:color="#color/tab_selected" />
</selector>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="tab_selected">#036DAB</color>
<color name="tab_unselected">#f36f25</color>
</resources>
Try to use uppercase letters in your colors instead of lowercase letters.
<color name="tab_unselected">#F36F25</color>
Related
It isn't looking nice when using EditText enabled="false". How can I change it
automatically for all of the controls?
I've added this image for reference.
Can someone help me? Thanks.
Create a custom selector in drawables and set it as
<EditText android:textColor="#drawable/edit_text_selector" />
1) in 'colors.xml' define the color for enabled and disabled state:
<color name="enabled_color">#F7FE2E</color>
<color name="disabled_color">#000000</color>
2) in 'drawable/edit_text_selector.xml':
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="#color/disabled_color"/>
<item android:color="#color/enabled_color"/>
</selector>
3) in your layout.xml:
<EditText
android:id="#+id/customEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:text="Hello!"
android:textColor="#drawable/edit_text_selector" />
In the color file define your color:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="#color/disabled_color" />
<item android:color="#color/normal_color"/>
</selector>
In the layout:
<EditText
android:text="whatever text you want"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#drawable/example" />
</EditText>
I'm confused with the answers to this question.
I have the following in values-14/styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
<style name="ListTheme" parent="AppTheme">
<item name="android:activatedBackgroundIndicator">#drawable/br_listitem</item>
</style>
</resources>
then I have defined in my drawable dir br_listitem.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/SlateBlue" android:state_activated="true"/>
</selector>
and finally in my listitem.xml file I have
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="600dp"
android:gravity="left|center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:paddingLeft="5dp"
style="#style/ListTheme"
android:background="?android:attr/activatedBackgroundIndicator">
I get a light orange color when pressed and light green after. The activated background works, but it's not using my colors...
Thanks !
~ Jay
Based on comments I made the following changes. I pulled the style out of the LinearLayout and put it in my listview as follows:
<ListView
style="#style/ListTheme"
android:id="#+id/XYZList"
android:layout_height="600dp"
android:layout_width="600dp"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_gravity="center|top"
android:layout_row="2"
android:layout_rowSpan="10"
android:focusable="true"
android:choiceMode="multipleChoice"
android:background="#80D0D0D0"
>
</ListView>
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"
I am creating a custom ListView as below
Main Layout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ListView android:id="#+id/listview"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_margin="3dip"
android:fadingEdge="none"
android:soundEffectsEnabled="true"
android:clickable="true"
android:scrollbars="none"
android:divider="#ffcccccc"
android:dividerHeight="1dip"
android:layout_weight="1"/>
</LinearLayout>
Custom ListView
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/sellistitem">
<TextView
android:id="#+id/ListItem"
android:layout_width="wrap_content"
android:layout_height="30dip"
android:layout_margin="1dip"
android:textColor="#color/BLACK"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="5dip"/>
</RelativeLayout>
and Selector as below
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/BLUE" />
<item android:drawable="#drawable/WHITE" />
</selector>
The Drawable
<resources>
<drawable name="WHITE">#ffffff</drawable>
<drawable name="BLUE">#ff0033cc</drawable>
</resources>
Having done this the selection part works fine. However when I click on any item ,the selected item blinks twice before actually changing to blue. It doesn't change to blue directly as it should. How can I remove this blinking effect?
Regards,
try this android:cacheColorHint="#00000000" to listview
Selectors are tricky, in general. Try this for your selector instead:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_enabled="true"
android:drawable="#drawable/selected_background" />
<item android:state_focused="false"
android:state_pressed="false"
android:state_selected="false"
android:state_checked="false"
android:state_enabled="true"
android:state_checkable="false"
android:drawable="#drawable/normal_background"/>
</selector>
Note that the android:drawable attribute does not have to be a drawable. If it's a simple color you can reference it with the #color/background_color format.
EDIT:
Ok, those white and blue "drawables" aren't drawables, they're just colors, you're better off defining them in the colors.xml. It could be that that is actually the reason for the flickering.
<resources>
<color name="blue">#ff0033cc</color>
<color name="white">#ffffff</color>
</resources>
I am trying to make my buttons change the color of their text when it is pressed but i ran into a problem that i cant solve. I get an error saying "unable to resolve color value" then it gives me the path to the file. here are my files im using
This one is in a new folder named color under resources and its called button
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#ffff0000" />
<item android:state_focused="true" android:color="#ff0000ff" />
<item android:color="#ff000000" />
</selector>
And
<Button android:text="Main Menu" android:textColor="#color/button"
android:layout_width="200px" android:id="#+id/mainmenu"
android:layout_height="55px" android:layout_x="5dip"
android:layout_y="174dip"
android:textSize="18px">
</Button>
its driving me crazy if anybody could help me.
I successfully did it like this:
Files:
/drawable/button_states.xml
/layout/main.xml
/values/colors.xml
button_states.xml:
<?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/red" /> <!-- pressed -->
<item android:state_focused="true"
android:color="#color/blue_background" /> <!-- focused -->
<item android:color="#color/white" /> <!-- default -->
</selector>
colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="blue_background">#FF2f74c3</color>
<color name="white">#fefefe</color>
<color name="red">#ff0000</color>
</resources>
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_height="wrap_content"
android:text="Button"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:textColor="#drawable/button_states" />
</LinearLayout>
Try android:background instead.