Button color not change... ( Android) - java

I was working on a project I can create a round button and set the gradient color but when I use it in Button background the color not changed.
rounded_shape.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:startColor="#9bbbc1"
android:centerColor="#456268"
android:endColor="#456268"
android:angle="270" />
<corners
android:radius="25dp" >
</corners>
</shape>
Button in Xml
<Button
android:id="#+id/btn1"
android:layout_below="#+id/edttxt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="2dp"
android:layout_marginRight="80dp"
android:layout_marginBottom="2dp"
android:background="#drawable/rounded_shape"
android:padding="12dp"
android:paddingTop="2dp"
android:paddingEnd="2dp"
android:paddingBottom="4dp"
android:text="Analyse"
android:textAllCaps="false"
android:textColor="#android:color/white"
android:textSize="20dp"
android:textStyle="italic"></Button>

Try it in rounded_shape.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="12dip" />
<stroke android:width="1dip" android:color="#333333" />
<gradient android:angle="-90" android:startColor="#333333" android:endColor="#555555" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="12dip" />
<stroke android:width="1dip" android:color="#333333" />
<solid android:color="#58857e"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="12dip" />
<stroke android:width="1dip" android:color="#333333" />
<gradient android:angle="-90" android:startColor="#333333" android:endColor="#555555" />
</shape>
</item>
</selector>

The AppCompat library helps with bringing modern theming to your app on all Android versions, so change Button to androidx.appcompat.widget.AppCompatButton:
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btn1"
android:layout_below="#+id/edttxt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="2dp"
android:layout_marginRight="80dp"
android:layout_marginBottom="2dp"
android:background="#drawable/rounded_shape"
android:padding="12dp"
android:paddingTop="2dp"
android:paddingEnd="2dp"
android:paddingBottom="4dp"
android:text="Analyse"
android:textAllCaps="false"
android:textColor="#android:color/white"
android:textSize="20dp"
android:textStyle="italic”/>

Related

Change background of bottomnavigationtab

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 :

How do I add animation / styling to a button? Android Studio

I have a button
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="45dp"
android:onClick="loginIsClicked"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:background="#drawable/button"
android:text="#string/Auth"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16sp"
android:enabled="false" />
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/red"/>
<corners android:radius="10dp"/>
</shape>
How can I add animation to the button used in the default buttons?
Example:
enter image description here
If I understood correctly, what you are looking for is a ripple. Wrap your shape in a ripple as follows and provide your ripple color:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/rippleColor">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/red"/>
<corners android:radius="10dp"/>
</shape>
</item>
</ripple>
Add MaterialButton.
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Button" />
Also do not forget to change theme Theme.AppCompat.Light.DarkActionBar to Theme.MaterialComponents.Light.DarkActionBar in styles.xml file.

Giving shadow effect to a custom view

Hi i am developing an app where i have a custom curve shape which i'm using in an imageview now this shpae is in white color and i have created another similar custom shape in black color so now what i'm trying to do is make the black shape as shadow of white shape as a thin black line acting as a outline to white shape.
Now my problem is when i run the app the black shape is getting completely overlapped by white shape.
So please f anyone can help me out here
My xml code
<android.support.v4.widget.NestedScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:id="#+id/profile_scroll"
xmlns:android="http://schemas.android.com/apk/res/android" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/background_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#drawable/curved_toolbar"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:src="#drawable/curved_toolbar"
android:visibility="gone" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:layout_marginBottom="20dp"
android:src="#drawable/profile_black_shadow"/>
<ImageView
android:id="#+id/second_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:layout_marginBottom="20dp"
android:src="#drawable/profile_second_image" />
<ImageView
android:id="#+id/pencil_image"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_marginTop="25dp"
android:src="#drawable/pencil" />
</RelativeLayout>
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circle_image"
android:layout_width="116dp"
android:layout_height="120dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="125dp"
android:layout_marginRight="125dp"
android:layout_marginTop="113dp"
android:src="#drawable/heath_ledger"
/>
<LinearLayout
android:id="#+id/person_name_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:layout_below="#+id/circle_image"
android:layout_centerInParent="true"
>
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Jhon Doe"
android:id="#+id/person_name_text"
android:textColor="#color/White"
android:textSize="16sp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/points_layout"
android:layout_marginBottom="8dp"
android:layout_below="#+id/person_name_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="6dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="20dp">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/first_follow_count"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="200"
android:textColor="#color/White"
android:layout_marginLeft="13dp"
android:textSize="15sp"/>
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/first_follow_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="13sp"
android:text="Followers"
android:textColor="#color/White"
android:layout_marginTop="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="51dp">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/second_follow_count"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="200"
android:layout_marginLeft="40dp"
android:textColor="#color/White"
android:textSize="15sp"/>
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/second_follow_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="13sp"
android:text="Following"
android:textColor="#color/White"
android:layout_marginLeft="25dp"
android:layout_marginTop="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="100dp">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/third_follow_count"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="1.5K"
android:textColor="#color/White"
android:textSize="15sp"/>
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/third_follow_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="13sp"
android:text="Points"
android:textColor="#color/White"
android:layout_marginTop="5dp"/>
</LinearLayout>
</LinearLayout>
<View
android:id="#+id/divider_view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/black"
android:layout_above="#+id/leaderboard_recycler"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/leaderboard_recycler"
android:layout_below="#+id/points_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</android.support.v7.widget.RecyclerView>
<View
android:id="#+id/divider_view1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/black"
android:layout_below="#+id/leaderboard_recycler"
/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
and my custom white shape
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<size
android:width="30dp"
android:height="15dp"/>
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"/>
</shape>
and my black shape
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#000000"/>
<size
android:width="18dp"
android:height="9.1dp"/>
<corners
android:bottomLeftRadius="55dp"
android:bottomRightRadius="55dp"
/>
</shape>
Try with this drawable (You can adjust shadow thickness by change padding in shapes),
like:-
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="0px">
<layer-list>
<item android:top="4dp">
<shape android:shape="rectangle">
<solid android:color="#08000000"/>
<corners
android:bottomLeftRadius="180dp"
android:bottomRightRadius="180dp" />
<size
android:width="80dp"
android:height="40dp"/>
<padding
android:bottom="3px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#09000000"/>
<corners
android:bottomLeftRadius="180dp"
android:bottomRightRadius="180dp" />
<size
android:width="80dp"
android:height="40dp"/>
<padding
android:bottom="2px"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#10000000"/>
<corners
android:bottomLeftRadius="180dp"
android:bottomRightRadius="180dp" />
<size
android:width="80dp"
android:height="40dp"/>
<padding
android:bottom="2px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#11000000"/>
<corners
android:bottomLeftRadius="180dp"
android:bottomRightRadius="180dp" />
<size
android:width="80dp"
android:height="40dp"/>
<padding
android:bottom="1px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#12000000"/>
<corners
android:bottomLeftRadius="180dp"
android:bottomRightRadius="180dp" />
<size
android:width="80dp"
android:height="40dp"/>
<padding
android:bottom="1px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#13000000"/>
<corners
android:bottomLeftRadius="180dp"
android:bottomRightRadius="180dp" />
<size
android:width="80dp"
android:height="40dp"/>
<padding
android:bottom="1px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#14000000"/>
<corners
android:bottomLeftRadius="180dp"
android:bottomRightRadius="180dp" />
<size
android:width="80dp"
android:height="40dp"/>
<padding
android:bottom="1px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#15000000"/>
<corners
android:bottomLeftRadius="180dp"
android:bottomRightRadius="180dp" />
<size
android:width="80dp"
android:height="40dp"/>
<padding
android:bottom="1px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#16000000"/>
<corners
android:bottomLeftRadius="180dp"
android:bottomRightRadius="180dp" />
<size
android:width="80dp"
android:height="40dp"/>
<padding
android:bottom="1px" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#17000000"/>
<corners
android:bottomLeftRadius="180dp"
android:bottomRightRadius="180dp" />
<size
android:width="80dp"
android:height="40dp"/>
<padding
android:bottom="1px" />
</shape>
</item>
</layer-list>
</item>
<item >
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
<corners
android:bottomLeftRadius="180dp"
android:bottomRightRadius="180dp" />
<size
android:width="80dp"
android:height="40dp"/>
</shape>
</item>
</layer-list>
Set on ImageView like:-
<ImageView
android:background="#drawable/shape"
android:layout_width="match_parent"
android:layout_height="200dp" />
Result:-

Set width SeekBar Android

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>

Buttons design like in Jeepsing

I'm trying to create buttons in Android the same way as in Jeepsing application for iPhone using linear layout but without success. Maximum that I get is three separated buttons the same size.
I need three buttons without background, separated only by their borders when two of them have one rounded corner like on the following screenshot:
This is my last try:
<LinearLayout android:id="#+id/LinearLayout02" android:layout_height="wrap_content" android:layout_width="match_parent">
<Button android:id="#+id/Button04" android:text="Button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"></Button>
<Button android:id="#+id/Button05" android:text="Button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"></Button>
<Button android:id="#+id/Button06" android:text="Button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"></Button>
</LinearLayout>
I also tried GridLayout but without success.
just create shapes with corners radius for both pressed/released effects..
<solid android:color="#77000000" />
<corners android:radius="10dip" />
<gradient
android:angle="-90"
android:endColor="#44FF0000"
android:startColor="#CCFF0000" />
<padding
android:bottom="10dip"
android:left="10dip"
android:right="10dip"
android:top="10dip" />
<stroke
android:width="1dip"
android:color="#000000" >
</stroke>
for more info about shapes refer this
After creating shapes for pressed/released effects create a XML file for button selector like following example
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#drawable/prs_arrival_fb_btn" /> <!-- pressed -->
<item
android:state_focused="true"
android:drawable="#drawable/prs_arrival_fb_btn" /> <!-- focused -->
<item
android:drawable="#drawable/arrival_fb_content_btn" /> <!-- default -->
</selector>
then set this selector to your button as background.. like the following example..
<Button android:text="Play" android:id="#+id/playBtn"
android:background="#drawable/button_selector"
android:textColor="#ffffff" />
This is how I achieved it:
up_left_button_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/up_left_button_shape_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/up_left_button_shape_pressed"
android:state_selected="true" />
<item android:drawable="#drawable/up_left_button_shape_released" />
</selector>
up_left_button_shape_pressed.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ff0000ff"
android:endColor="#ff0000ff"
android:angle="45"/>
<padding android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
<corners android:radius="8dp"
android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp"
android:topLeftRadius="8dp" android:topRightRadius="0dp"/>
<stroke android:width="2dp" android:color="#ff444444"/>
</shape>
up_center_button_shape_released.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#00000000"
android:endColor="#00000000"
android:angle="45"/>
<padding android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
<corners android:radius="8dp"
android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp"
android:topLeftRadius="8dp" android:topRightRadius="0dp"/>
<stroke android:width="2dp" android:color="#ff444444"/>
</shape>
Center and right button shapes are the same, just need to play with which corners to round.
And finally the view layout:
<TableRow android:id="#+id/buttonsRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp">
<RelativeLayout android:id="#+id/buttonsRowRelativeLayout"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<Button
android:id="#+id/leftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/save"
android:textColor="#ffffffff"
android:background="#drawable/up_left_button_selector"
android:layout_toLeftOf="#+id/centerButton" />
<Button
android:id="#+id/centerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/change"
android:textColor="#ffffffff"
android:background="#drawable/up_center_button_selector"
android:layout_centerHorizontal="true"/>
<Button
android:id="#+id/rightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/send"
android:textColor="#ffffffff"
android:background="#drawable/up_right_button_selector"
android:layout_toRightOf="#+id/centerButton" />
</RelativeLayout >
</TableRow>
And it looks pretty good.

Categories