How can I change the DrawableLeft image of a button using selectors?
I'm using the below selector file and a shape XML for drawable. When the button is clicked, the image doesn't change.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="#drawable/toolbar_button_pressed"
android:drawableLeft="#drawable/ic_selected" />
<item android:state_pressed="true"
android:drawable="#drawable/toolbar_button_pressed"
android:drawableLeft="#mipmap/ic_selected" />
<item android:drawable="#drawable/toolbar_button_normal" />
</selector>
toolbar_button_pressed
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="10dp" />
<solid android:color="#color/primary_dark" />
<padding android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
<stroke android:width="1dp"
android:color="#color/divider" />
</shape>
Layout Button
<Button android:id="#+id/background_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_background"
android:drawableLeft="#drawable/ic_background"
style="#style/ToolbarButton"
android:drawablePadding="10dp"
android:singleLine="true"
android:layout_weight="1" />
I was able to solve this using selectors:
<Button android:id="#+id/style_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/style_button_text"
android:drawableLeft="#drawable/toolbar_drawable_left"
style="#style/ToolbarButton"
android:layout_weight="1" />
/res/drawable/toolbar_drawable_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="#drawable/ic_about_highlight"/>
<item android:state_pressed="true"
android:drawable="#drawable/ic_about_highlight"/>
<item android:drawable="#drawable/ic_about" />
</selector>
Related
I try to put a border for a button in android but unfortunately I can't see the button border.
Drawable File 👇
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="12dp" />
<stroke android:width="3px" android:color="#7E8082" />
</shape>
</item>
</selector>
XML 👇
<Button
android:id="#+id/btn_signup"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="122dp"
android:background="#drawable/bg_signup"
android:fontFamily="#font/poppins_semibold"
android:text="Create an Account"
android:textAllCaps="false"
android:textColor="#color/black"
app:layout_constraintTop_toBottomOf="#+id/btn_login" />
You don't need to use a custom drawable, just use a MaterialButton:
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
app:strokeColor="#7E8082"
app:strokeWidth="1dp"
app:cornerRadius="12dp"/>
Don't use a selector for single option use shape directly
bg_signup
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#cdcdcd"/>
<corners
android:radius="4dp"
/>
<stroke
android:width="1dp"
android:color="#000"
/>
</shape>
use Style attribute instead of android:background="#drawable/bg_signup"
make a custom style then call it android:style="#style/bg_signup"
I need to get such result as here
I tried do like this :
my bottom_nav_menu_bg
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/home_btn_bg" android:state_checked="true" />
<item android:drawable="#color/gray_900"/>
</selector>
My BottomNavView
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_menu"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_weight="1"
app:itemBackground="#drawable/bottom_navigation_menu_bg"
android:background="#color/gray_900"
app:menu="#menu/bottom_navigation"
app:itemIconTint="#drawable/tab_color"
app:itemTextColor="#drawable/tab_color"
android:backgroundTint="#null"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
my home_btn_bg for getting gradient color
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#color/black"
android:endColor="#color/light_green_100"
android:angle="90" />
</shape>
but i got smth like that :
I'm using VerticalSeekBar and I would like to set the width.
With the term width I mean the width of the seekbarbar progress part.
This is my xml
<com.h6ah4i.android.widget.verticalseekbar.VerticalSeekBarWrapper
android:layout_width="wrap_content"
android:layout_height="350dp"
android:layout_below="#+id/btnDate"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dp">
<com.h6ah4i.android.widget.verticalseekbar.VerticalSeekBar
android:id="#+id/verticaleDate"
android:layout_width="0dp"
android:layout_height="0dp"
app:seekBarRotation="CW270"
android:max="10"
android:splitTrack="false"/>
</com.h6ah4i.android.widget.verticalseekbar.VerticalSeekBarWrapper>
Thanks for interesting.
background_fill.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:centerColor="#FF555555"
android:endColor="#FF555555"
android:startColor="#FF555555" />
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
progress_fill.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:centerColor="#FFB80000"
android:endColor="#FFFF4400"
android:startColor="#FF470000" />
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
progress.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/background_fill"/>
<item android:id="#android:id/progress">
<clip android:drawable="#drawable/progress_fill" />
</item>
</layer-list>
thumb.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<gradient
android:angle="270"
android:endColor="#E5492A"
android:startColor="#E5492A" />
<size
android:height="20dp"
android:width="20dp" />
</shape>
Update your seekbar layout by this:
<com.h6ah4i.android.widget.verticalseekbar.VerticalSeekBarWrapper
android:layout_width="wrap_content"
android:layout_height="350dp"
android:layout_below="#+id/btnDate"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dp">
<com.h6ah4i.android.widget.verticalseekbar.VerticalSeekBar
android:id="#+id/verticaleDate"
android:layout_width="0dp"
android:layout_height="0dp"
android:progressDrawable="#drawable/progress"
android:thumb="#drawable/thumb"
app:seekBarRotation="CW270"
android:max="10"
android:splitTrack="false"/>
</com.h6ah4i.android.widget.verticalseekbar.VerticalSeekBarWrapper>
How to change the text color of the keys?
Here is my keyboard layout.
<?xml version="1.0" encoding="UTF-8"?>
<android.inputmethodservice.KeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard"
android:keyBackground="#drawable/key_background"
android:background="#color/keyboard_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:keyPreviewLayout="#layout/preview" />
key_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Bottom 2dp Shadow -->
<item android:top="4dp"
android:left="2dp"
android:right="2dp">
<shape android:shape="rectangle" >
<solid android:color="#color/key_shadow" />
<corners android:radius="4dp"/>
</shape>
</item>
<!-- White Top color -->
<item android:bottom="4px"
android:top="4dp"
android:left="2dp"
android:right="2dp">
<shape android:shape="rectangle" >
<solid android:color="#color/white" />
<corners android:radius="4dp" />
</shape>
</item>
</layer-list>
Please look into this you will get an idea for your problem.
http://developer.android.com/reference/android/inputmethodservice/KeyboardView.html
android:keyTextColor="your color code"
U can use android:keyTextColor attribute: like
android:keyTextColor="#android:color/black"
In my app i need to display toggle button that looks like this (this one is for checked state) http://s58.radikal.ru/i159/1308/dc/e3cb45e9a71f.jpg, dark color is parent view background.
It must be just a colored circle with 50x50 size, but for checked state it must include that blue border outside. The whole button must be always 70x70, so it has enough space for border. I guess i have to use simple shape drawable for default state and layer-list drawable for checked state, but it doesnt work for me, it just creates some kind of stretched oval and without any border(like this http://s019.radikal.ru/i619/1308/50/0f02f9ab2ea4.jpg). Here is the code i'm using for ToggleButton background:
first_board_color_dot.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/first_board_color_dot_checked"></item>
<item android:drawable="#drawable/first_board_color_dot_default"></item>
</selector>
first_board_color_dot_checked.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:innerRadius="34dp"
android:shape="ring"
android:thickness="2dp" >
<solid android:color="#color/first_player_dot_color" />
</shape>
</item>
<item>
<shape android:shape="oval" android:gravity="center">
<solid android:color="#color/first_board_color" />
<size
android:height="50dp"
android:width="50dp" />
</shape>
</item>
</layer-list>
first_board_color_dot_default.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="oval" android:gravity="center">
<solid android:color="#color/first_board_color" />
<size
android:height="50dp"
android:width="50dp" />
</shape>
</item>
</layer-list>
this is how i'm setting up button
<ToggleButton
android:id="#+id/board_color_button1"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:text=""
android:textOn=""
android:textOff=""
android:background="#drawable/first_board_color_dot"
android:checked="true"
android:onClick="boardColorButtonClicked"/>
i cannot understand what im doing wrong...