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>
Related
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>
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 am using CardView to show List Items, where each and every List Item contains two textviews, namely - BOOK NOW/BOOK and DETAIL/DETAILS.
I would like to achieve rounded bottom TextView, but getting in rectangular shape
I have to design something like this:
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:layout_margin="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="2dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1">
.......
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:background="#color/more"
android:layout_weight="1">
<TextView
android:id="#+id/btnBook"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="BOOK"
android:textColor="#android:color/background_light"
android:padding="5dp"
android:background="#null"
android:textAppearance="?android:textAppearanceMedium"
android:gravity="center" />
<TextView
android:id="#+id/btnDetail"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="DETAILS"
android:background="#null"
android:textColor="#android:color/background_light"
android:padding="10dp"
android:textAppearance="?android:textAppearanceMedium"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Where I have to make change to get it done ?
set this background to the LinearLayout containing the textViews
<item>
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimary" />
<corners android:bottomLeftRadius="cardview_corner_radius_value"
android:bottomRightRadius="cardview_corner_radius_value" />
</shape>
</item>
and add background of TextView as transparent
You have to make selector for this in drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="2dp" android:color="#color/more" />
<dotted android:color="#00FF0000" />
<padding android:bottom="1dp"/>
</shape>
</item>
</layer-list>
Then set background to your view. Use this
android:background="#drawable/corner_selector"
instead of
android:background="#color/more"
make a file rounded_border.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="#color/common_border_color" />
<solid android:color="#fff" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:radius="5dp" />
</shape>
and keep it as a background of linear layout
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_border"
android:layout_weight="1">
1. make button.xml file and put it in drawable folder
<?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="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<gradient android:angle="-90" android:startColor="#345953" android:endColor="#689a92" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<solid android:color="#58857e"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#58857e" />
</shape>
</item>
</selector>
2. then change your xml background of Linearlayout
android:background="#color/more"
to
android:background="#drawable/button"
Try with this simplest way to do this your Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/btnbackground"
android:layout_margin="20dp"
android:text="My Profile"
/>
</LinearLayout>
after that make a xml in drawable folder btnbackground.xml
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/llabeforeclick3"
android:state_pressed="true"/>
<item android:drawable="#drawable/llaafterclick3"/>
</selector>
then make another llabeforeclick3.xml in drawable directory
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#19384A" >
</solid>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topRightRadius="10dp"
android:topLeftRadius="10dp" />
<stroke
android:width="0dp"
android:color="#19384A" />
<padding
android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp"
android:color="#19384A" />
</shape>
after that make another xml llaafterclick3.xml in drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
//background color
<solid android:color="#204A60" >
</solid>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topRightRadius="10dp"
android:topLeftRadius="10dp" />
//before clicked
<gradient
android:angle="45"
android:centerColor="#204A60"
android:centerX="20"
android:centerY="20"
android:endColor="#204A60"
android:gradientRadius="25"
android:startColor="#204A60" />
</shape>
if some buddy wants to make more rounded corners then use to increase size of
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topRightRadius="10dp"
android:topLeftRadius="10dp"
That solve here your color code is depends on you you need to put color code only and radious.
I want to draw a vertical dotted line in xml, using shape.
I used this example:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<size
android:height="400dp"
android:width="4dp"/>
<stroke
android:color="#000000"
android:dashWidth="100dp"
android:dashGap="10dp" />
</shape>
Then:
<View android:id="#+id/vertical_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/dotted_line"
android:layout_marginLeft="27dp"/>
But it doesn't work. How can I do it?
I tried a few things, I liked the drawable solutions and found that this worked.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="-8dp"
android:bottom="-8dp"
android:left="-8dp">
<shape>
<solid android:color="#android:color/transparent"/>
<stroke
android:width="4dp"
android:color="#df0000"
android:dashGap="4dp"
android:dashWidth="4dp"/>
</shape>
</item>
</layer-list>
The trick is the negative top bottom and left values as these are set outside of the object now, leaving a single dashed line.
Its used in the following view.
<View
android:layout_width="4dp"
android:layout_height="match_parent"
android:background="#drawable/dash_line_vertical"
android:layerType="software" />
Try this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<size
android:height="400dp"
android:width="4dp" />
<stroke
android:dashGap="10dp"
android:dashWidth="100dp"
android:color="#000000" />
</shape>
Then use like this
<LinearLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#drawable/dot_line"
android:orientation="vertical" >
</LinearLayout>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90" >
<shape android:shape="line" >
<stroke
android:color="#000000"
android:dashWidth="100dp"
android:dashGap="10dp"/>
</shape>
</rotate>
I have one big layout, and one smaller layout inside of it.
How do I create a line border around the small layout?
Sure. You can add a border to any layout you want. Basically, you need to create a custom drawable and add it as a background to your layout. example:
Create a file called customborder.xml in your drawable folder:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
<stroke android:width="1dp" android:color="#CCCCCC"/>
</shape>
Now apply it as a background to your smaller layout:
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/customborder">
That should do the trick.
Also see:
http://tekeye.biz/2012/add-a-border-to-an-android-layout
How to add border around linear layout except at the bottom?
Creat XML called border.xml in drawable folder as below :
<?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="#FF0000" />
</shape>
</item>
<item android:left="5dp" android:right="5dp" android:top="5dp" >
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
</layer-list>
then add this to linear layout as backgound as this:
android:background="#drawable/border"
Try this:
For example, let's define res/drawable/my_custom_background.xml as:
(create this layout in your drawable folder) layout_border.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke android:width="2dp" android:height="2dp"
android:color="#FF0000" />
<solid android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
<corners android:radius="1dp" android:bottomRightRadius="5dp"
android:bottomLeftRadius="0dp" android:topLeftRadius="5dp"
android:topRightRadius="0dp" />
</shape>
</item>
</layer-list>
main.xml
<LinearLayout
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#drawable/layout_border" />
</LinearLayout>
Create a one xml file in drawable folder
<stroke
android:width="2dp"
android:color="#B40404" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<corners android:radius="4dp" />
Now call this xml to your small layout background
android:background="#drawable/yourxml"
This solution will only add the border, the body of the LinearLayout will be transparent.
First, Create this border drawable in the drawable folder, border.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android= "http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="2dp" android:color="#ec0606"/>
<corners android:radius="10dp"/>
</shape>
Then, in your LinearLayout View, add the border.xml as the background like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/border">
you can do it Pragmatically also
GradientDrawable gradientDrawable=new GradientDrawable();
gradientDrawable.setStroke(4,getResources().getColor(R.color.line_Input));
Then set the background of layout as :
LinearLayout layout = (LinearLayout ) findViewById(R.id.ayout); layout .setBackground(gradientDrawable);
I'll add Android docs link to other answers.
https://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
It describes all attributes of the Shape Drawable and stroke among them to set the border.
Example:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="1dp" android:color="#F00"/>
<solid android:color="#0000"/>
</shape>
Red border with transparent background.
Don't want to create a drawable resource?
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:minHeight="128dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:background="#android:color/white">
<TextView ... />
</FrameLayout>
</FrameLayout>
Try This in your res/drawable
<?xml version="1.0" encoding="UTF-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<padding android:left="15dp"
android:right="15dp"
android:top="15dp"
android:bottom="15dp"/>
<stroke android:width="10dp"
android:color="#color/colorPrimary"/>
</shape>
</item><item android:left="-5dp"
android:right="-5dp"
android:top="-5dp"
android:bottom="-5dp">
<shape android:shape="rectangle">
<solid android:color="#color/background" />
</shape></item></layer-list>
Nobody seems to be using the method we came up with so I thought I would share, as it involves much simpler code.
Simply nest one layout inside another with padding, and the outer one can be colored, making a frame.
<androidx.appcompat.widget.LinearLayoutCompat
android:id="#+id/llSignatureBorder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/black"
android:orientation="vertical"
android:padding="4dp">
<com.yourmom.mobiledriverapp.Controls.SignatureArea
android:id="#+id/signatureArea"
android:layout_width="#dimen/signaturearea_width"
android:layout_height="#dimen/signaturearea_height"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp" />
</androidx.appcompat.widget.LinearLayoutCompat>