I would like to put a fade black covering my image, just like this one, with a text, a fade background and then my image. I just want to know how to implement this fade. Thank you!
Just create a drawable file, I'll name it gradient_background (you can set any name)
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:startColor="#000000"
android:centerColor="#00000000"
android:endColor="#00000000"/>
</shape>
then inside your target xml, create a View like this one, look that inside it, we're setting the background as your drawable file. In this case is gradient_background
<View
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#drawable/gradient_background"
app:layout_constraintBottom_toBottomOf="post_image"
app:layout_constraintEnd_toEndOf="#+id/post_image"
app:layout_constraintStart_toStartOf="post_image"
app:layout_constraintTop_toTopOf="#+id/post_image" />
So it should look like this:
:)
First, Make bottom_transparent_gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient android:angle="270"
android:endColor="#64000000"
android:startColor="#android:color/transparent" />
</shape>
</item>
</selector>
Then, add that drawable as your view background in which you want to show the fade background effect.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bottom_transparent_gradient"/>
And that's it! You can see the result you wanted. :)
Related
I am developing a small app in Android Studio, but I can't change the button color. I've tried everyting, changing only the background, the backgroundtint, to make a new drawable object, but I can't seem to find any answer, this is my button XML layout:
<Button
android:id="#+id/calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="55dp"
android:layout_marginTop="45dp"
android:background="#drawable/round_green_shape"
android:text="CALCULA">
</Button>
And this is the XML for my background:
<?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="#color/buttonsGreen">
</solid>
<corners
android:radius="15dp">
</corners>
</shape>
But this is how my bottons look:
And on the app they look the same:
I would appreciate any help,
Thank you
Done, i just had to delete the
android:background = ""
and just set the:
android:backgroundTint = ""
to green...
i create this xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#color/light_blue"
android:centerColor="#color/dark_blue"
android:endColor="#color/light_purple"
>
</gradient>
<corners
android:radius="30dp">
</corners>
</shape>
</item>
</selector>
and i trying to set this file to my button background.but problem is background dose not accept colors of xml file.it is use backgroundTint colors and not the colors i set above.
THIS IS MY ACTIVITY_XML
<Button
android:id="#+id/temp_l"
android:layout_width="250dp"
android:layout_height="33dp"
android:background="#drawable/temp_shape"
app:layout_constraintBottom_toTopOf="#+id/scrollView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.143" />
i searched in youtube and saw that eveyone did what i did but they get result and im not.
sorry about my english.its not very well.
I guess you are using android:backgroundTint="#null" with android namespace, but you need to set app:backgroundTint="#null" with app namespace instead
Side note:
You should wrap the xml drawable into a layer-list as long as you have no need to the selector, so you might change it to:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:centerColor="#055D93"
android:endColor="#color/light_purple"
android:startColor="#color/light_blue" />
<corners android:radius="30dp">
</corners>
</shape>
</item>
</layer-list>
Preview
All the view classes on Android are define in rectangle shape.When you touches it detects in the rectangle zone,when you set image it fills the rectangle.How to make a class which is round by default?
Features I am looking for:
Support all the ImageView functions
Square Image input with setImageBitmap or onDraw are converted to round.
Dectect circular touch zone instead of sqaures
Small in size and overhead.
3rd Party is fine but prefer just use interal library.
Create a shape inside your drawable package.
// res/drawable/circle.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="1.9"
android:useLevel="false" >
<solid android:color="#android:color/transparent" />
<stroke
android:width="10dp"
android:color="#android:color/white" />
</shape>
Then create a layer list inside the drawable
// res/drawable/img.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/circle"/>
<item android:drawable="#drawable/ic_launcher"/>
</layer-list>
Then create the image view with layer list
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/img"/>
How can I create this exact drawable in java code only?
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="1dp" />
<solid android:color="#ff0000" />
<padding
android:bottom="-15px"
android:top="-5px" />
</shape>
I need the padding values to be variable so I can't do it as an xml.
If you wanna draw something custom, you should open a Canvas and make your drawing there.
Read this:
https://developer.android.com/training/custom-views/custom-drawing.html
And it seems a simple shape. So you can add a layout view (View,TextView, ImageView, etc.) set background with this drawable and adjust padding through this view.
On an Android View, I want to have a some clickable text that works similar to a webpage hyperlink.
It looks just like normal text (no button border), but when touched, I want the text color to change and I may also want its background to turn a reverse color.
Is it better to use a Button with a transparent background or a TextView. When should I choose one over the other?
Thanks much
you can use Button and make selector for background and text both.
textselector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#0000ff"/> <!-- pressed -->
<item android:state_focused="true" android:color="#android:color/white"/> <!-- focused -->
<item android:color="#android:color/white"/> <!-- default -->
</selector>
buttonselector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#android:color/white"/> <!-- pressed -->
<item android:state_focused="true" android:color="#0000ff"/> <!-- focused -->
<item android:color="#0000ff"/> <!-- default -->
</selector>
In your layout xml
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonselector"
android:text="some text"
android:textColor="#drawable/textselector" />
hotveryspicy gave a great answer and really pointed me in the right direction. Thank you, but I had a few issues with the response.
What I want is a button that has Black text and a Gray background in its normal state and a Red background with White text in its selected state. Like this:
Using hotveryspicy's suggestions I had the following issues:
I get an error when trying to assign a drawable to textColor. Funny but I see other references to doing this sort of thing. Maybe the XML validation is stricter now?
I also got an error if I didn't define a android:drawable in the buttonselector.xml. It seems you can set the color of a drawable in a selector eiter, you need to actually create a drawable.
Anyhow this is what I did:
I created a Color State Resource that looks like this:
File: res/colors/link_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#ffffff"/>
<item android:color="#000000"/>
</selector>
Then the following 3 drawables:
My button background in its normal state using a Shape Drawable:
File: res/drawable/link_button.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#cccccc"/>
</shape>
My button background in its selected state, also a Shape Drawable:
File: res/drawable/link_button_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ff0000"/>
</shape>
Then I created a Drawable Selector that chooses between the 2 shapes.
File: res/drawable/link_button_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/link_button_selected"
android:state_pressed="true" />
<item
android:drawable="#drawable/link_button" />
</selector>
Then in my layout my button looks like this:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Button"
android:textColor="#color/link_button"
android:background="#drawable/link_button_selector"
/>
Thanks for the help everyone!
Add String like
<string name="link">'Google'</string>
In your layout
<TextView
android:id="#+id/link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:linksClickable="true"
android:text="#string/link" />
You can linkify your text using the linkify class.
Have a look at this and this with few examples
For Google's sake:
Rather than make a button look like a link why not make a TextView clickable? This was effectively what I wanted and worked for my use. I wanted text to be clickable to spawn an intent.
TextView.setOnClickListener(new View.OnClickListener()