I have a recylcerview with borders, and i want to add an animation to the bordered area only, how do i add it? I want to add android:foreground="?attr/selectableItemBackground" such that when row is clicked, only the bordered area displays the animation, not the whole row
Recycler View
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recycler_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
Row item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/pokedex_row"
android:padding="10sp"
android:clickable="true"
android:focusable="true"
android:background="#drawable/card_background"
android:elevation="12dp"
android:foreground="?attr/selectableItemBackground"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pokedex_row_text_view"
android:layout_margin="10sp"
/>
</LinearLayout>
background of row
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="8dp"
android:right="3dp"
android:top="8dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#CBAAAAAA"
android:width="1dp"/>
<corners android:radius="5dp" />
</shape>
</item>
<item
android:left="5dp"
android:right="5dp"
android:top="5dp"
android:bottom="5dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/white" />
<corners android:radius="5dp" />
</shape>
</item>
</layer-list>
You could use the ripple tag instead of layer-list to acheive the required behaviour.
Note: This will work only for API 21+(Lollipop).
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:targetApi="lollipop" android:color="?colorControlNormal">
<item
android:left="8dp"
android:right="3dp"
android:top="8dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#CBAAAAAA"
android:width="1dp"/>
<corners android:radius="5dp" />
</shape>
</item>
<item
android:left="5dp"
android:right="5dp"
android:top="5dp"
android:bottom="5dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/white" />
<corners android:radius="5dp" />
</shape>
</item>
Related
can someone tell me how to create a custom toolbar like this .
how to add that custom toolbar?
this is my xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/praktik"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
android:fitsSystemWindows="true">
<include layout="#layout/content_main_games"/>
</LinearLayout>
Use this design to set background.
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#00B0EA" />
</shape>
</item>
<item
android:bottom="400dp"
android:left="-100dp"
android:right="-100dp"
android:top="-200dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:angle="90"
android:endColor="#65FFFFFF"
android:startColor="#65FFFFFF" />
</shape>
</item>
<item
android:bottom="402dp"
android:left="-100dp"
android:right="-100dp"
android:top="-280dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#FFFFFF" />
</shape>
</item>
I am trying shadow text view like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="top|center"
android:background="#drawable/gradient">
<TextView
android:layout_width="300dp"
android:layout_height="50dp"
android:text="#string/ph"
style="#style/TextBox"
android:textSize="16sp"/>
</LinearLayout>
gradient.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<gradient
android:endColor="#FFFFFF"
android:startColor="#FFFFFF"
android:type="linear"
android:centerColor="#E3F2FD"
android:angle="90">
</gradient>
</shape>
</item>
This code can't get my design. Is it possible to textview like my picture?
Here i tried to create same shadow as your requirement which will look like this. I know the shadow color is not blur as u want
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/shadow"
android:orientation="vertical"
android:paddingBottom="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rectangle_shape"
android:padding="10dp"
android:text="Phone Number" />
</LinearLayout>
drawable/shadow.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#220000ff" />
<corners android:radius="20dp" />
</shape>
drawable/rectangle_shape.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF" />
<corners android:radius="20dp" />
</shape>
make xml backround_with_shadow and paste this code-
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape
android:shape="rectangle">
<solid android:color="#87ceeb" />
<corners android:radius="5dp"/>
</shape>
</item>
and set xml as background of layout
<item android:right="1dp" android:left="1dp" android:bottom="2dp">
<shape
android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
I'm using a pop up window as Activity class with a layout, when the button is pressed, a pop up window will appear. what I want is to edit the shape of my pop up window that is a RelativeLayout. thanks
this is my pop_up.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/layout_shape"
tools:context="com.example.computer.mathkiddofinal.FinalResults.Final_Result_Grade_4">
</RelativeLayout>
this is my layout_shape
<solid
android:color="#00B0BE" >
</solid>
<stroke
android:width="2dp"
android:color="#C4CDE0" >
</stroke>
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" >
</padding>
<corners
android:radius="40dp" >
</corners>
</shape>
A screenshot from my XML, i want to remove that whitespace on the side, i know its from the layout background, can i use transparency? because this will pop up on other layout activity so i need only is the blue shape. btw the layout code is from #Sabari thanks
Try this:-
Add a custom drawable
custom_shape.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#00B0BE" >
</solid>
<stroke
android:width="2dp"
android:color="#C4CDE0" >
</stroke>
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" >
</padding>
<corners
android:radius="40dp" >
</corners>
</shape>
And add background for the RelativeLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/transparent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/custom_shape">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Testing" />
</RelativeLayout>
</RelativeLayout>
Just change your,
layout_shape as below,
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listview_background_shape">
<stroke
android:width="2dp"
android:color="#ff207d94" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
<corners android:radius="5dp" />
<solid android:color="#2eb8b8"></solid>
<corners android:radius="30dp"></corners>
</shape>
pop_up.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000">
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/layout_shape"
tools:context="com.example.computer.mathkiddofinal.FinalResults.Final_Result_Grade_4">
</RelativeLayout>
</RelativeLayout>
You just need to reduce the radius of the corners in the custom shape
<corners android:radius:"10dp"></corners>
I have some EditText in my code and I want to make the bottom border of it a bit thinner. Couldn't find anything about it in the Internet, maybe anyone here can help me with it.
What I have:
What I want:
Try like this for focus effects:
edt_bg_selector.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/edt_bg_selected" android:state_focused="true"/>
<item android:drawable="#drawable/edt_bg_normal" android:state_focused="false"/>
</selector>
edt_bg_normal.xml :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="1dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape android:shape="rectangle" >
<stroke
android:width="1px"
android:color="#FF000000" />
<solid android:color="#00FFFFFF" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
</item>
</layer-list>
edt_bg_selected.xml :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="1dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape android:shape="rectangle" >
<stroke
android:width="1px"
android:color="#ff0000" />
<solid android:color="#00FFFFFF" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
</item>
</layer-list>
and change your edit text like:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edt_bg_selector" />
Try like this below:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:hint="Biografie"
android:textColorHint="#99000000"
android:drawableLeft="#drawable/quote_img" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#80000000" />
</LinearLayout>
Or
keep this btm_line_shape.xml in your drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="1dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape android:shape="rectangle" >
<stroke
android:width="1px"
android:color="#FF000000" />
<solid android:color="#00FFFFFF" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
</item>
</layer-list>
and
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Biografie"
android:textColorHint="#99000000"
android:background="#drawable/btm_line_shape"
android:drawableLeft="#drawable/quote_image" />
I want to get Item in layer-list which is in xbutton.xml.
button.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="5dp" android:left="5dp" android:bottom="6dp" android:top="5dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="3dip" android:color="#FFF" />
<solid android:color="#003055"/>
<corners android:radius="22dp" />
</shape>
</item>
<item android:right="10dp" android:left="10dp" android:bottom="11dp" android:top="10dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:angle="90"
android:endColor="#0184c9"
android:startColor="#003055"
android:type="linear" />
<corners android:radius="19dp" />
</shape>
</item>
<item android:left="-30dp" android:top="20dp" android:id="#+id/itemIcon">
<bitmap android:src="#drawable/coin" android:gravity="center"></bitmap>
</item>
</layer-list>
main_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_hdpi"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:layout_marginTop="25dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:orientation="horizontal">
<Button
android:id="#+id/list1button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:textSize="16sp"
android:background="#drawable/xbutton"
android:drawablePadding="#dimen/activity_horizontal_margin"
android:gravity="left|center_vertical"
android:drawableLeft="#drawable/ikona1"
style="#style/ButtonShadowText"
android:onClick="onClickBtn"/>
</LinearLayout>
</RelativeLayout>
When I try to get item by
View itemCoin = findViewById(R.id.itemIcon);
I get null for itemCoin. I want to change the android:left value in item.
I can get other view i.e. list1button.
final LayerDrawable exampleDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.example);
final ClipDrawable d1 = (ClipDrawable) exampleDrawable.findDrawableByLayerId(R.id.customitemIcon);
findDrawableByLayerId is for searching layers in drawable and findViewById is for VIEWS