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>
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 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.
i am creating a rounded linear layout with some buttons and textviews, i have used a custom selector as background of layout. My problem is that layout have extra space on corners how to remove this? any help will be appreciated
here is my code
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp"
>
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"
/>
<stroke android:width="2dip"
android:color="#color/#275D69"/>
</shape>
Layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/selector"
/>
Current output:
Dont want that space where i have placed red marks.
With below code you have rounded background with least space on corner
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#FFFFFF" />
<corners android:radius="5dp" />
<stroke
android:width="2dip"
android:color="#275D69" />
</shape>
this may include space on corner but it's too low.
just reduce radius value.
Try to use this approach, is not the most clear solution but for me works:
Create a Layout container with transparent background, and use it as a container of your rounded layout
<LinearLayout
.....
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/transparent"
......>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/selector"
android:orientation="vertical">
<!-- content of the rounded ll -->
</LinearLayout>
</LinearLayout>
The white spaces should be disappeared
Here is a solution you need to follow:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp" />
<stroke
android:width="2dip"
android:color="#275D69"/>
</shape>
Now in main xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:margin="10dp"
android:background="#drawable/selector"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
Problem solved!
You can make rounded corners using cardView
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="6dp"
app:cardCornerRadius="5dp"
app:cardBackgroundColor="#D3D3D3"
app:cardPreventCornerOverlap="false"
card_view:cardPreventCornerOverlap="false">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp" />
</android.support.v7.widget.CardView>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp" />
<stroke android:width="0dip"
android:color="#color/#275D69"/>
</shape>
<corners android:radius="6dip" />
Put corner radius whatever you want.
After getting pissed for 2 days I finally found it .
It cannot be solved by any drawable files or by editing the canvas but simply by making the layout as base layout.
There are several methods and stuffs under values you have to choose the right ones and add it in your styles.
First add these to your styles.xml
<style name="AppBottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="bottomSheetStyle">#style/CustomBottomSheetStyle</item>
</style>
<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">#drawable/drawable_round_bottom_sheet</item>
</style>
Now the most important part is to call the AppBottomDialogue for this I used this
override fun getTheme(): Int {
return R.style.AppBottomSheetDialogTheme
}
Now you can choose whatever to do with your method I used ImagesView inside ConstraintLayout you can directly clip it no problem.
I want to draw a line as ImageView's background.But it doesn't work?
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<solid android:color="#FF0000FF" />
<size android:width="10dp"
android:height="2dp"/>
</shape>
Just a demo.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/dividing_line"
android:layout_marginLeft="10dp" />
ImageView has no content so size will be 0x0dp. If you want a divider try setting the width to match_parent and the height to whatever you feel comfortable with (2dp for example).
Update: Try this.
In your layout file:
<ImageView
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="#drawable/dividing_line"
android:layout_marginLeft="10dp" />
The drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<stroke android:width="2dp" android:color="#0000FF"/>
<size android:height="2dp" />
</shape>
It is working for me.
As pointed out by TheTool if you just want a divider the easier solution is to add
<View android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/yourColor" />
to your layout file.
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" />