I have a circle png that I put as a background image in a TextView. However, the image shows up transparent even when I tried setting the alpha level to "1". Is there something wrong I did in my XML code?
<TextView
android:id="#+id/timeline_text_details_img"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginTop="25dp"
android:background="#drawable/circle"
android:gravity="center"
android:textColor="#fff"
android:textSize="14dp"
android:alpha="1"
android:textStyle="bold" />
The circle png I want needs to be thick white like how it originally is
but instead it looks like this when I run it
You can simply create a shape circle.xml and place it in drawable.
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="2dp"
android:color="#android:color/white"
/>
<solid
android:color="#000000"/>
</shape>
You can change the color scheme as you like.
Related
I have a background drawable which has just two corners of it with a radius.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:topLeftRadius="6dp" android:bottomLeftRadius="6dp"></corners>
</shape>
I apply it on a textview. I also attach an outlineprovider to it .
<android.support.v7.widget.AppCompatTextView
android:id="#+id/textView71"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="64dp"
android:background="#drawable/left_rounded_border_6dp"
android:backgroundTint="#color/colorAccent"
android:padding="#dimen/unit_medium"
android:elevation="10dp"
android:outlineProvider="bounds"
android:text="Challenge"
android:textAppearance="#style/TextAppearance.Heading5"
android:textColor="#color/colorTextWhite"
app:layout_constraintBottom_toTopOf="#+id/company_logo_iv"
app:layout_constraintEnd_toStartOf="#+id/textView73"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
This the shadow I see.
On close inspection you'd see that the shadow is not applied exactly at the curves. Rather it is applied on a rectangular area.
I am not sure why would that be .
Elevation creates shadows based on the view's outline provider. This defaults to the bounds of the background drawable - which is perfectly rectangular.
You can create and set your own outline provider with rounded corners - see https://developer.android.com/training/material/shadows-clipping#Shadows
create a drawable shape file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="#color/grey_light_background"
android:centerColor="#color/grey_light_background"
android:startColor="#color/grey_light_background"
android:angle="90" />
<corners
android:radius="#dimen/dimen_15dp"
/>
</shape>
apply to text view background,
android:background="#drawable/background_grey_rounded_corner_15dp"
I have used the following code to add ripple effect to my button, but the border around it has disappeared and the button has merged with the back ground. I want to add border around it to distinguish it.
This is the code of my button:
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:textColor="#ffffff"
android:text="#string/action_sign_in" />
This is the drawable for the button:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="1dp"
android:bottomRightRadius="1dp"
android:radius="0.1dp"
android:topLeftRadius="1dp"
android:topRightRadius="1dp" />
<solid android:color="#android:color/transparent" />
<stroke
android:width="1dp"
android:color="#E8E6E7" />
</shape>
You can actually have both by using background and foreground properties, like so:
android:background="#drawable/the_name_of_your_button_file"
android:foreground="?android:attr/selectableItemBackground"
android:background="?attr/selectableItemBackground"
is causing the button to take on the theme, and blend into the background as if transparent. You are not pointing to the drawable file for the button, which has the stroke element, which gives the border.
If you want a border, you must use the stroke element in your drawable by pointing to it with:
android:background="#drawable/the_name_of_your_button_file"
I'm trying to create a rounded image button using the code below which works when you don't declare a src image. However when you do, it just places the image in but without the rounding effect on it.
style.xml
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="#+id/imageButton1"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp"
android:src="#drawable/ellyfish"
android:background="#drawable/roundcorner"
/>
roundcorner.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#33DDFF" />
<corners android:radius="50dp" />
</shape>
Make your src image round, or make it transparent so you can see the rounded background behind it.
for background of first button i have used shape which is below
1) left_round_shape_button.xml
<solid android:color="#0084ff" />
<corners
android:radius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:bottomRightRadius="0dp"
android:topRightRadius="0dp" />
</shape>
for setting background of second button i have used below code
2) right_round_shape_button.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- you can use any color you want I used here gray color -->
<solid android:color="#0084ff" />
<corners
android:radius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:bottomRightRadius="0dp"
android:topRightRadius="0dp" />
</shape>
Now when i set this into buttons
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<Button
android:id="#+id/btnSticker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/left_round_shape_button"
android:text="Sticker"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btnMySticker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/right_round_shape_button"
android:text="My Sticker" />
</LinearLayout>
but these are not looking proper :(
why first button is coming with all round shape and why second is not coming :(
from android docs i have read following
Note: Every corner must (initially) be provided a corner radius greater than 1, or else no
corners are rounded. If you want specific corners to not be rounded, a work-around is to use
android:radius to set a default corner radius greater than 1, but then override each and every
corner with the values you really want, providing zero ("0dp") where you don't want rounded corners.
Finally i got the solution, it's problem with XML rendering, when u run your app, you will get proper output,
I need to put a orange line in the left side of a imageview. I put in "the hard way" and it works:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp" >
<LinearLayout
android:layout_width="5dp"
android:layout_height="fill_parent"
android:background="#FF7F24" >
</LinearLayout>
<ImageView
android:id="#+id/image1"
android:layout_width="50dp"
android:layout_height="60dp"
/>
</LinearLayout>
There is a way to do this effect using a drawable xml file in the image directly without using the linearlayouts?
Thanks for your help!
Use this below code as a drawable to imageview
<item>
<shape android:shape="rectangle" >
<solid android:color="#FF7F24" />
</shape>
</item>
<item android:left="5dp">
<bitmap android:shape="rectangle"
android:src="#drawable/image"/>
</item>
You can always create a shape and set it as the background of your LinearLayout instead of "#FF7F24".
But since you only want a solid color, I think the way you implemented it is just fine