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.
Related
Hello I'm trying to achieve this look but with no success maybe you could help me out and Thank you for you time!
Desired look:
And my approach was
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="45"
android:endColor="#cf6c6c6c"
android:startColor="#53414141"/>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topRightRadius="10dp"
/>
</shape>
</item>
<item android:gravity="right"
android:height="10dp"
android:width="10dp">
<bitmap android:src="#drawable/flag_uk"/>
</item>
</layer-list>
Please try below drawable xml code:
Drawable file:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:right="25dp">
<shape
android:shape="rectangle">
<corners android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topRightRadius="10dp"/>
<gradient
android:angle="45"
android:endColor="#cf6c6c6c"
android:startColor="#53414141"/>
</shape>
</item>
<item
android:top="10dp"
android:left="90dp"
android:bottom="10dp"
android:right="15dp">
<bitmap android:src="#drawable/flag_uk"/>
</item>
</layer-list>
And use this drawable to TextView or LinearLayout, I am using LinearLayout:
Layout XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity"
android:background="#88ffffff"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button"
android:paddingLeft="20dp"
android:paddingRight="40dp"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="coin"
android:textColor="#ffffff"
android:textSize="25sp"/>
</LinearLayout>
</LinearLayout>
**Output:*
<gradient
android:angle="45"
android:endColor="#cf6c6c6c"
android:startColor="#53414141"/>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topRightRadius="10dp"
/>
</shape>
</item>
<item android:gravity="right|center_vertical"
android:height="10dp"
android:width="10dp">
<bitmap android:src="#drawable/flag_uk"/>
</item>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/some_drawable"
android:text="coin"
android:paddingStart="10dp"
android:paddingEnd="20dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:layout_margin="10dp"/>
Photo is zoomed hence pixalated
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 trying to change my ListView item's visual but it doesn't change, I'm using this tutorial http://ryanharter.com/blog/2013/01/31/how-to-make-an-android-card-list/ but my listview item doesn't change.
I made the bg_card.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="2dp"/>
<solid android:color="#ccc" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="2dp" />
<solid android:color="#android:color/white" />
<padding android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp" />
</shape>
</item>
</layer-list>
and put in my ListView but this doesn't change the visual, was thus:
My listview is:
<ListView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/listView"
android:dividerHeight="5dp"
android:layout_margin="16dp"
android:background="#drawable/bg_card"
/>
Please if someone has a suggestion, I don't know how to deal with this issue.
Thank you
Set the background to the listItem layout, not to the listview.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/bg_card"
>
<ImageView
android:id="#+id/image"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<TextView
android:id="#+id/text"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</LinearLayout>
I have custom designed EditText
search_page.xml
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:background="#E1E1E1"
android:weightSum="1" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:text="City" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#drawable/rounded_edittext"
android:layout_weight=".75" />
</LinearLayout>
rounded_edittext.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
</shape>
I want to use color code #2f6699 to get a border color like an outline to the EditText text box as below:
Any ideas on how to achieve this?
Use the below code in your rounded_edittext.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke
android:width="1dp"
android:color="#2f6699" />
<corners
android:radius="10dp"
/>
</shape>
This should work
For EditText in image above, You have to create two xml files in res-->drawable folder.
First will be "bg_edittext_focused.xml" paste the lines of code in it
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke
android:width="2dip"
android:color="#F6F6F6" />
<corners android:radius="2dip" />
<padding
android:bottom="7dip"
android:left="7dip"
android:right="7dip"
android:top="7dip" />
</shape>
Second file will be "bg_edittext_normal.xml" paste the lines of code in it
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#F6F6F6" />
<stroke
android:width="2dip"
android:color="#F6F6F6" />
<corners android:radius="2dip" />
<padding
android:bottom="7dip"
android:left="7dip"
android:right="7dip"
android:top="7dip" />
</shape>
In res-->drawable folder create another xml file with name "bg_edittext.xml" that will call above mentioned code. paste the following lines of code below in bg_edittext.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/bg_edittext_focused" android:state_focused="true"/>
<item android:drawable="#drawable/bg_edittext_normal"/>
</selector>
Finally in res-->layout-->example.xml file in your case wherever you created your editText
you'll call bg_edittext.xml as background
<EditText
:::::
:::::
android:background="#drawable/bg_edittext"
:::::
:::::
/>
Use the below code in your rounded_edittext.xml :
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="0dp"
android:shape="rectangle">
<stroke android:width="2dp"
android:color="#2F6699"/>
<corners android:radius="3dp" />
<gradient android:startColor="#C8C8C8"
android:endColor="#FFFFFF"
android:type="linear"
android:angle="270"/>
</shape>
android:background="#E1E1E1"
// background add in layout
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff">
</EditText>
edit_text.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
<corners android:radius="5dp"/>
<stroke android:width="2dip" android:color="#color/button_color_submit" />
</shape>
use here
<EditText
-----
------
android:background="#drawable/edit_text.xml"
/>
Use a 9-patch drawable or create a Shape drawable.
I want to create Button with background.png and rounded corners. How to do this?
I wrote this code on MainActivity:
<Button
android:layout_width="match_parent"
android:layout_height="40dip"
android:text="LOGIN TO THE GAME"
android:textColor="#ffffff"
android:background="#drawable/button_corners" />
And i create file 'button_corners.xml' which contain:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:radius="10dip" />
<stroke
android:width="0.5dp"
android:color="#000000" />
</shape>
And now how to add background-image to this button? Help!
Buttons with rounded corners and a picture, I've never used. But with buttons with background with colors, without any images, I used this code:
On Activity:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Ementas"
android:background="#drawable/button_corners"/>
And on file 'button_corners.xml':
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:padding="10dp" >
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
<gradient
android:startColor="#color/green_dark"
android:endColor="#color/green_light"
android:angle="270" />
</shape>
And I still have a file with colors:
<resources>
<color name="green_dark">#98B505</color>
<color name="green_light">#5F7102</color>
</resources>
The final result like this:
I think to use images, the code should not be too different.
Use a Linear Layout(A) and set whatever image you have as it's background. Then use another Linear Layout(B) to place inside Linear Layout(A) and give that Layout a background with rounded corners.
<LinearLayout
android:id="#+id/A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/whateverimage"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/B"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/roundedstuff"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
roundedstuff.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#00000000"
android:endColor="#00000000" />
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp" />
<stroke
android:width="2dp"
android:color="#ffffff" />
<corners
android:bottomRightRadius="10dp"
android:radius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
Save that to drawable folder