Why are there opaque areas?
I made a custom drawable,
but the same phenomenon as the image occurred.
i test phone Samsung A30, Pixel 4a
drawable/alarm_list_reward_start.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="2.0dp"
android:color="#000000" />
<solid android:color="#FFEB2A" />
<corners android:radius="10.0dp" />
</shape>
</item>
</layer-list>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="12.0dp"
android:layout_marginEnd="12.0dp"
android:layout_marginBottom="50.0dp">
<TextView
android:id="#+id/rewardBtn"
android:layout_width="match_parent"
android:layout_height="44.0dp"
android:focusable="false"
android:background="#drawable/alarm_list_reward_start"
android:gravity="center"
android:textColor="#000000"
android:textSize="15.0dp"
android:textStyle="bold" />
</RelativeLayout>
This is happening, as you are using android:layout_width="match_parent". You can solve this issue by using wrap_content. Or you could set custom width and height of the layer list, such as,
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size android:width="152dp" android:height="152dp" />
<solid android:color="#00FFFFFF" />
<stroke android:width="2.0dp" android:color="#000000" />
<solid android:color="#FFEB2A" />
<corners android:radius="10.0dp" />
</shape>
</item>
</layer-list>
Related
This drawable :
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#70628b" />
<stroke android:width="12dp"
android:color="#4c3f6e"
/>
<corners android:radius="8dp"/>
</shape>
This is my textview
<TextView
android:id="#+id/tv_disabled_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/disabled_transparent_frame"
android:fontFamily="#font/inter_medium"
android:gravity="center"
android:padding="#dimen/dp_24"
android:text="02 : 45"
android:textColor="#color/white"
android:textSize="#dimen/dp_32"
android:textStyle="bold"
android:visibility="visible" />
I am trying to apply circular drawable in inside and outside but given code its showing only outer :
Current screen using this code :
Expected screen
I am unable to do circular please help me in this .
try this code
It can show nested corner
<?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="#4c3f6e" />
<corners android:radius="8dp" />
<padding
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#70628b" />
<corners android:radius="8dp" />
</shape>
</item>
</layer-list>
note that your "expected screen" has some small shadow under inner color area, you won't achieve this with common drawable, even with layer-list
I would advice you to use CardView
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/outer_background"
android:padding="12dp">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="4dp"
android:visibility="gone"
app:cardCornerRadius="8dp"
app:cardBackgroundColor="#70628b">
<TextView ...
adjust elevation param for more/less shadow
outer_background.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#4c3f6e" />
<corners android:radius="8dp"/>
</shape>
be pixel-perfect, build beautiful apps!
Here is my Button:
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/status1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/large_text"
android:text="#string/offline"
android:drawableEnd="#drawable/online_dot"
android:drawableTint="#color/colorOnline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
online_dot.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#color/colorOnline" />
<stroke android:width="1dp" android:color="#color/colorLightBlack"/>
<corners android:radius="#dimen/circle_radius" />
</shape>
</item>
</selector>
online_dot.xml doesn't show. If I change drawableEnd to an actual image (not drawable) then it works. But I want to show a shape.
How can I fix this?
It happens because your shape hasn't a defined size.
You have to specify the size inside online_dot.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#color/colorOnline" />
<stroke android:width="1dp" android:color="#color/colorLightBlack"/>
<corners android:radius="#dimen/circle_radius" />
<!-- Specify the shape size here. -->
<size
android:height="20dp"
android:width="20dp" />
</shape>
</item>
</selector>
I want to make a shape like in the below image. Size in the graphic is as below
The circle/Oval size is 30px
The rounded rectangle height is 20px and width is 65px
The rectangle start is set to the circle center so in total graphic size will be 80px.
However, for drawable I need responsive size so I can use it for any
size of the view.
I am able to create a shape by overlapping that gives a similar illusion. I am not sure if types of boolean (graphics) is possible in android or not.
Drawable XML
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size
android:width="75dp"
android:height="30dp" />
<solid android:color="#android:color/transparent" />
</shape>
</item>
<item android:right="60dp">
<shape android:shape="oval">
<solid android:color="#color/colorPrimary" />
<size
android:width="30dp"
android:height="30dp" />
</shape>
</item>
<item android:left="15dp" android:top="10dp" android:bottom="10dp">
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimary" />
<size
android:width="66dp"
android:height="20dp" />
<corners
android:bottomRightRadius="20dp"
android:topRightRadius="20dp" />
</shape>
</item>
</layer-list>
The above XML producing shape as in below screenshot
When I set the shape to View it output as in below screenshot
Layout XML
<View
android:layout_width="80dp"
android:layout_height="30dp"
android:background="#drawable/shape_flask"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Output
As you can see, even defining size in drawable and view shape doesn't stick to the size aspect ration. I am sure it is me who is doing anything wrong.
Question: How can I make the drawable shape that works on any size of view keeping aspect ration the same as it is in the Graphic
reference. And how to add Drop Shadow to it.
EDITED
I have fixed some size issue but the shape still has a problem. For better visualization, I set different colors for both shapes.
Drawable XML
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size
android:width="80dp"
android:height="30dp" />
<solid android:color="#android:color/transparent" />
</shape>
</item>
<item android:right="60dp">
<shape android:shape="oval">
<solid android:color="#color/colorPrimary" />
<size
android:width="30dp"
android:height="30dp" />
</shape>
</item>
<item android:left="15dp" android:top="5dp" android:bottom="5dp">
<shape android:shape="rectangle">
<solid android:color="#color/colorAccent" />
<size
android:width="66dp"
android:height="20dp" />
<corners
android:bottomRightRadius="20dp"
android:topRightRadius="20dp" />
</shape>
</item>
</layer-list>
But as you can see in the below screenshot of the view it doesn't output the same size and position. However, the View code is the same.
How about splitting drawables like this?
layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:id="#+id/oval"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/shape_oval" />
<TextView
android:id="#+id/rec"
android:layout_width="65dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/oval"
android:layout_toRightOf="#+id/oval"
android:background="#drawable/shape_rec"
android:layout_marginStart="-15dp"
android:layout_marginLeft="-15dp" />
</RelativeLayout>
shape_oval
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#color/colorPrimary" />
</shape>
shape_rec
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/colorAccent" />
<size
android:width="66dp"
android:height="20dp" />
<corners
android:bottomRightRadius="20dp"
android:topRightRadius="20dp" />
</shape>
Preview
I'm trying to set a transparent circle with a stroke as the background of a TextView in android:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:background="#drawable/decibel_circle"
android:text="30 dB"
android:fontFamily="sans-serif"
android:textColor="#android:color/black"
android:textSize="70dp" />
</RelativeLayout>
And this is the shape I want to use, located in decibel-circle.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="5dp"
android:color="#F44336">
</stroke>
<solid android:color="#android:color/transparent"/>
<size
android:width="36dp"
android:height="36dp" />
<corners android:radius="12dp" />
</shape>
</selector>
The problem is that the shape is never shown, neither in the preview nor when I run my app.
What am I doing wrong?
in your decibel-circle.xml remove selector just use shape alone
Use this only
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="5dp"
android:color="#F44336">
</stroke>
<solid android:color="#android:color/transparent"/>
<size
android:width="36dp"
android:height="36dp" />
<corners android:radius="12dp" />
</shape>
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" />