custom_email_icon.xml
<?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/ic_email_focused"/>
<item android:state_focused="false"
android:drawable="#drawable/ic_email"/>
</selector>
activity_main.xml
<EditText
android:id="#+id/emailText"
android:layout_width="301dp"
android:layout_height="48dp"
android:layout_marginTop="100dp"
android:ems="10"
android:background="#drawable/custom_input"
android:drawableStart="#drawable/custom_email_icon"
android:drawablePadding="12dp"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:hint="Email Address"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Icon color change not working when I clicked to text. Same problem with the password line.
Instead of a focused state, you can add a selector for a pressed and selected state like following
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:state_enabled="true"
android:drawable="#drawable/ic_email" />
<item android:state_window_focused="false"
android:state_enabled="false"
android:drawable="#drawable/ic_email" />
<item android:state_pressed="true"
android:drawable="#drawable/ic_email_focused" />
<item android:state_enabled="true"
android:state_focused="true"
android:drawable="#drawable/ic_email_focused" />
<item android:state_enabled="true"
android:drawable="#drawable/ic_email" />
<item android:state_focused="true"
android:drawable="#drawable/ic_email_focused" />
<item android:drawable="#drawable/ic_email" />
</selector>
All problem is this code line, I just removed it and fixed; idk why automatically its cames when I add vector.
android:tint="?attr/colorControlNormal"
Related
I want to change my default Rating bar Star(*) icon to another icon.
Can anybody help me out..
My Code: XML
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
style="#style/foodRatingBar"
android:isIndicator="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="86dp"
android:numStars="4" />
Styles.xml:
<style name="foodRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/selector</item>
<item name="android:minHeight">23dip</item>
<item name="android:maxHeight">25dip</item>
</style>
Selector.xml:
<?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/ic_fuel_gray"/>
<item
android:id="#android:id/secondaryProgress"
android:drawable="#drawable/ic_fuel_gray"/>
<item
android:id="#android:id/progress"
android:drawable="#drawable/ic_fuel_color"/>
</layer-list>
But outPut is:
Just add below two snippets and you are done:
<style name="customRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/custom_image1</item>
<item name="android:indeterminateDrawable">#drawable/custom_image2</item>
</style>
and Use above style in your xml where rating bar is used:
<RatingBar style="#style/customRatingBar" ... />
Add replace your Rating bar code with this and check if it is showing in preview?
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/customRatingBar"
/>
<RatingBar
android:id="#+id/ratingBar"
style="#style/foodRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:numStars="5"
android:rating="5"
android:transformPivotX="0dp"
android:transformPivotY="0dp"
android:isIndicator="false"/>
try this
I need to change checkbox from
to
I found that to change color of tick mark you have to put selectors:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="#drawable/checked" />
<item android:state_checked="false" android:drawable="#drawable/unchecked" />
</selector>
In xml:
<CheckBox
android:id="#+id/cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/your_selector"/>
create xml file
coustom_check_box.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="#drawable/checked" />
<item android:state_checked="false" android:drawable="#drawable/unchecked" />
</selector>
In checkbox set android:button property to the custom_checkbox_design.xml drawable like
android:button="#drawable/coustom_check_box"
<CheckBox
android:id="#+id/checkBoxCustomized1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Coustom Checkbox"
android:checked="true"
android:button="#drawable/coustom_check_box"
android:textSize="20dp" />
icons
Create a drawable custom_cheackbox:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/checkbox_not_selected"android:state_checked="false"/>
<item android:drawable="#drawable/checkbox_selected" android:state_checked="true"/>
<item android:drawable="#drawable/checkbox_not_selected"/>
</selector>
add your custom background inside custom_checkbox android:button="#drawable/custom_cheackbox"
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="#drawable/checkbox_selector"
android:text="CheckBox"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/Black" />
I want to show active image when I clicked button.But ,if I am not clicked,to show normal image style.How can I do that ?Please help me kindly.
icon_home_config.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/home_button_hover" />
<item android:state_focused="true" android:drawable="#drawable/home_button_hover" />
<item android:drawable="#drawable/home_button"/>
</selector>
ImageView
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/btn_background" />
btn_background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/btn_default_disabled_focused" android:state_focused="true" android:state_enabled="false"/>
<item android:drawable="#drawable/btn_default_focused" android:state_focused="true" android:state_enabled="true"/>
<item android:drawable="#drawable/btn_default_disabled" android:state_enabled="false"/>
<item android:drawable="#drawable/btn_default_pressed" android:state_pressed="true"/>
<item android:drawable="#drawable/btn_default_normal" />
</selector>
use this background.xml selector & put it in drawable folder & set image background to this selector.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/pressed" android:state_pressed="true"/>
<item android:drawable="#drawable/normal" android:state_focused="true"/>
<item android:drawable="#drawable/normal"/>
</selector>
OR
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#drawable/normal" />
<stroke
android:width="0dp"
android:color="#drawable/pressed" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
set image background
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/background" />
I've got the following button:
<Button
android:id="#+id/searchCompaniesButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/company_icon"
android:drawablePadding="10dp"
android:drawableRight="#drawable/next_icon_big"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:backgroud="#drawable/transparent_button_selector"
android:paddingRight="10dp"
android:text="#string/searchCompanies" />
transparent_button_selector is transparent_button_selector.xml in /drawable-ldpi folder:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/lightGrey"
android:state_pressed="true" />
<item android:drawable="#color/veryLightGrey"
android:state_focused="true" />
<item android:drawable="#null" />
</selector>
Also I've got a colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="lightGrey">#3d3d3d</color>
<color name="veryLightGrey">#4d4d4d</color>
</resources>
But when I run my app, log will say:
'item' tag requires a 'drawable' attribute"
What the hell? I know there are few similar questions, but answers are not helpful. I tried:
Restarting Eclipse
Cleaning projects
Running app at real device(crush)
Replace this:
<item android:drawable="#null" />
with:
<item android:drawable="#color/transparent" />
and add transparent color in your color file with code: #00000000
The drawable attribute always takes #drawable.i.e
you have to replace
<item android:drawable="#color/..."
android:state_pressed="true" />
with
<item android:drawable="#drawable/..."
android:state_pressed="true" />
Use this,
<item
android:state_pressed="true"
android:drawable="#drawable/selected_state" />
Then make a shape in drawable folder with name "selected_state" like this.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/lightGrey" />
</shape>
Your android:background attribute is misspelled:
android:backgroud="#drawable/transparent_button_selector"
The letter 'n' is missing in 'background'
I know there are many questions of this kind here, but I really dont know the reason that my code is not working.
I'm trying to make a button with three states: normal, pressed and released. When I say released, I mean that I would like to make this like a toogle button, with the states active and not active.
When I release the button, it returns to the default state. I would like to change the image by click, as a checkButton works.
I tried this:
http://blog.androgames.net/40/custom-button-style-and-theme/
http://www.gersic.com/blog.php?id=56
Android: How to Create a Custom button widget
http://techdroid.kbeanie.com/2010/03/custom-buttons-on-android.html
custom_buttom.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="false" android:drawable="#drawable/focussed" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="#drawable/focussedandpressed" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="#drawable/pressed" />
<item android:drawable="#drawable/default" />
</selector>
layout.xml:
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/menu"
android:layout_weight="1" android:background="#drawable/custom_button"></Button>
You are using android:state_focused and android:state_pressed.
What about android:state_checked?
You want custom something like Checkbox, right? In that case, you need two image for state check true and false, and a transparent file for background (which have no content, just has the same size as other images). Create two drawable selector file have content like this:
background_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/your_bg" />
</selector>
state_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_focused="true"
android:drawable="#drawable/checkbox_on" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="#drawable/checkbox_off" />
<item android:state_checked="false"
android:drawable="#drawable/checkbox_off" />
<item android:state_checked="true"
android:drawable="#drawable/checkbox_on" />
</selector>
Put these xml to your drawable folder, and in your layout, create a checkbox:
<CheckBox
android:layout_width="50dip"
android:layout_height="50dip"
android:background="#drawable/background_selector"
android:button="#drawable/state_selector"
/>
Hope this help ^_^