I am not able to find the exact sloution to make the shadow with the blurr. I am using the simple Concept of displaying the shadow , but only getting the simple shadow without the blurr.How can the shadow be made blurr without using the bitmap images.
main layout
<*********.CustomFontLoginButton
android:id="#+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/buttonbordershadow"
android:clickable="true"
android:gravity="center"
android:padding="15dp"
android:text="Login"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="14sp" />
buttonbordershadow
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/shadow_button"/>
<item
android:drawable="#drawable/round_button_login"
android:bottom="10px" />
</layer-list>
shadow_button
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#59282323"/>
<corners android:radius="2dp"/>
</shape>
round_button_login
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="90"
android:endColor="#8B0318"
android:startColor="#E31124"></gradient>
<corners android:radius="2dp" />
</shape>
I am able to get the simple shadow , How can i get the blurr shadow??
have a look on the following code. It might help you.
Related
This is Textview :
<TextView
android:id="#+id/text_naer_me"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=“Hello”
android:background="#drawable/rounded_white_border"
/>
This background resource
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#color/light_gray" />
<solid android:color="#color/white" />
<corners android:radius="2dp" />
</shape>
current view is below
enter image description here
expected view is below
enter image description here
please suggest me how to achieve this i want make textview as card view you can see my given screen
There are lots of ways and here they are Use that which one suits you
Create your own drawable
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">
<solid android:color="#android:color/darker_gray" />
<corners android:radius="5dp"/>
</shape>
</item>
<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>
and your_layout.xml
<TextView 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:orientation="horizontal"
android:padding="10dp"
android:background="#drawable/border"
/>
You can also use use a drawable from android
android:background="#android:drawable/toast_frame"
or:
android:background="#android:drawable/dialog_frame"
or:
android:background="#android:drawable/dialog_holo_light_frame"
Use a 9-patch image with a shadow and set it as the background to your
Linear layout
Use this website to create 9 patch with shadow
http://inloop.github.io/shadow4android/
Use android:elevation="20dp" and background same effect
like
cardview without wrap cardview
<TextView
android:layout_margin="10dp"
android:elevation="20dp"
android:padding="20dp"
android:background="#drawable/background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
/>
I am working on an Android app where I need to show some text inside circle like
The text is dynamic.Similarly I want to implement textview inside rectangle shape like
I found out that shape xml file can be used to draw some shapes like
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="20dip"/>
<stroke android:color="#color/colorPrimary" android:width="5dip"/>
<solid android:color="#android:color/transparent"/>
</shape>
But it is not proper as I want some empty space between text and circle.I also tried to use android:background in textview but could not achieve the above mentioned scenario.
What is the Best way to implement above scenario?
How such similar scenarios can be implemented?
Can I use some custom images so that circle/rectangle shapes can be changed and how to achieve this?
You can use something like this..
btn_bg.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="50dp" />
<solid android:color="#000"/>
</shape>
activity_main.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:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Total Count"
android:layout_marginTop="40dp"
android:textSize="36dp"
android:background="#drawable/btn_bg"
android:textColor="#fff"
android:id="#+id/btn"
/>
</RelativeLayout>
Try this:-
In your xml:-
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/test">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11"
android:layout_centerInParent="true"/>
</RelativeLayout>
#drawable/test
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="20dip"/>
<size android:height="40dp" android:width="40dp"/>
<stroke android:color="#color/colorPrimary" android:width="2dip"/>
<solid android:color="#android:color/transparent"/>
</shape>
As far as my knowledge aids me, there isn't any property to drop shadow around an EditText field, that can be set in the layout file. I searched for the problem and found solution that I've to provide a custom background xml drawable.
My drawable/background_with_shadow looks like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-lis xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape
android:shape="rectangle">
<solid android:color="#android:color/darker_gray" />
<corners android:radius="5dp"/>
</shape>
</item>
<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>
and I'm setting this property for my LinearLayout which contains an EditText
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_with_shadow">
<EditText>
.
.
</EditText>
<LinearLayout>
However it just drops the shadow around the bottom and bottom corners.
How would I do it for all the four sides and corners?
I'm trying to achieve this:
There are some better ways to get shadow around your edit text without using layer-list :
#1
Wrap your EditText in a CardView like this :
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="7dp"
android:layout_margin="10dp"
app:cardCornerRadius="0dp">
<EditText
android:id="#+id/msg_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:hint="Write a message"
android:paddingLeft="5dp"
android:paddingStart="5dp"
android:textColorHint="#c7c7c7"
android:textSize="15dp" />
</android.support.v7.widget.CardView>
OUTPUT :
2
Use a 9 patch as the background of your EditText :
<EditText
android:id="#+id/msg_box"
android:padding="20dp"
android:background="#drawable/shadow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:lines="5"
android:gravity="top"
android:hint="Enter your complaint..."
android:textColorHint="#a7a7a7"
android:textSize="15dp" />
OUTPUT
Read more about 9patch here.
Here's a great online tool to generate 9 patch shadow.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<item>
<shape>
<!-- set the shadow color here -->
<stroke
android:width="2.5dp"
android:color="#color/darker_gray" />
<!-- setting the thickness of shadow (positive value will give shadow on that side) -->
<!--Set shadow width as per your requirement -->
<padding
android:bottom="2dp"
android:left="0.5dp"
android:right="2dp"
android:top="0.5dp" />
<corners android:radius="2dp" />
</shape>
</item>
<!--White Background -->
<item>
<shape>
<solid android:color="#fff" />
<corners android:radius="2dp" />
</shape>
</item>
</layer-list>
Set this layout as your LinearLayout background.
I need to make the below shape using xml.
I have created an oval shape using below xml code.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
<item android:height="400dp"><shape
android:shape="oval">
<solid android:color="#000000" />
</shape></item>
</layer-list>
But I am not able to draw a line and circle together. Please help me to make the above shape using xml.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#color/comment_background"/>
<stroke android:color="#color/gray" android:width="0.5dp"/>
</shape>
This is Code for Creating Circle shape in android
Finally I have come with a solution after little googling.
Followed steps:-
1.Created a xml file called dot.xml in drawable folder to draw a dot or filled circle.
//Dot.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="#color/colorTimeline" />
</shape>
2.Inserted below code into layout file.
<View
android:id="#+id/v1"
android:layout_width="1dp"
android:layout_height="50dp"
android:background="#color/colorTimeline"
android:contentDescription="ad"
android:layout_marginStart="10dp"/>
<View
android:id="#+id/v2"
android:layout_width="16dp"
android:layout_height="16dp"
android:background="#drawable/dot"
android:contentDescription="f"
android:layout_marginStart="3dp"
android:layout_below="#id/v1"
android:layout_marginEnd="24dp"/>
<View
android:id="#+id/v3"
android:layout_width="1dp"
android:layout_height="50dp"
android:background="#color/colorTimeline"
android:contentDescription="ad"
android:layout_marginStart="10dp"
android:layout_below="#id/v2"/>
Final Output :-
Output Screenshot
My eyes bleeding, when i see your solution, sorry. I had to create and show you this one. Remember this example works only for known size of view. If you want to use dynamic values create my example drawable programatically.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- VERTICAL LINE -->
<item
android:left="9dp"
android:right="9dp">
<shape
android:shape="rectangle">
<solid
android:color="#FF0000" />
<size
android:width="2dp"
android:height="200dp" />
</shape>
</item>
<!-- OVAL -->
<item
android:top="90dp"
android:bottom="90dp">
<shape
android:shape="oval">
<solid
android:color="#FF0000" />
<size
android:width="20dp"
android:height="20dp" />
</shape>
</item>
</layer-list>
If you need any explanation just let me know.
I want to create the shape of autocomplete textview shown in the figure and text should come in center of it.
Currently I am trying to implement it as
<item>
<shape android:shape="rectangle" >
<corners android:radius="15dip" />
<solid android:color="#color/blue_text" />
<padding
android:bottom="5dip"
android:left="15dip"
android:right="15dip"
android:top="5dip" />
</shape>
</item>
<AutoCompleteTextView
android:id="#+id/autoComp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:background="#drawable/bg_autocompletetext"
android:textColor="#color/white"
</AutoCompleteTextView>
But it would just make the corners of the textview round. It does make it completely round. Please specify any solution for it.
try this code of shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:radius="100dp"/>
<solid
android:color="#2137FF"/>
<size
android:width="250dp"
android:height="60dp"/>
</shape>
try this tool
Its better to use 9 patch image as a background of your TextView.
With using 9 patch image you can set proper resolution for different resolution device.And it will give you better result .
You write a seperate xml layout(shape.xml) having code:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#DCDCDC" />
<stroke android:width="2.5dp"
android:color="#DCDCDC" />
<corners
android:radius="10dp"/>
</shape>
Then in your main layout add:
<AutoCompleteTextView
android:id="#+id/autoComp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:background="#drawable/shape"
android:textColor="#color/white"
</AutoCompleteTextView>
Hope this help.
Try this, working for rounded text view
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_textview.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#284A89" />
<corners
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
</shape>
Add Following file in drawables "searchtextbox_border.xml"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:radius="100dp"/>
<stroke android:color="#color/light_grey"
android:width="1dp">
</stroke>
</shape>
Then Add it as background in your AutocompleteTextview as follows:
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:padding="#dimen/padding_10dp"
android:background="#drawable/searchtextbox_border"
android:hint="Search" />