In generally android buttons are rectangular and on the mxl file what should I do if I want to make ring shaped or any other shaped button? or is there any tool that assure these to android developers which is open source (for now I'm seeking a ring-shaped button ).
create a new xml file inside your drawables, and put this code:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="15dp"
android:thickness="10dp"
android:useLevel="false">
<solid android:color="#fff" />
<size
android:height="50dp"
android:width="50dp" />
</shape>
now, use this as your image in an imageButton
You can also take a look at this:
android-state-list-generator
Related
I have a custom drawable using <shape> in xml, with the following code:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/blue"/>
<corners
android:radius="150dp"/>
</shape>
on a button, and I would like to programmatically change the button's color to another color while keeping the shape it gets from the custom drawable. Is this possible?
If you dont want to use the normal backgrounTint in your xml folder :
android:backgroundTint="yourcolor"
Use this Code in your java code :
yourbutton.setBackgroundTintList(this.getResources().getColorStateList(R.color.colorname));
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. :)
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.
It is possible to create contour around or shadow under VISIBLE pixels in ImageView.
In case this image in ImageView (outside from green figure is transparent):
I need next pic with border:
Please any code or references.
Dunno you just want to add a color as stroke to the background then you can do like this
If you are using color then you can create an xml file in the drawable in the res of your project
and create a drawable like this
Image.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="2dp"
android:color="#007cea" />
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
<solid android:color="#007cea" />
<corners android:radius="4dp" />
</shape>
And to your imageview you can call the xml file as
android:background="#drawable/login_button"
In the xml file you specify like this
<stroke
android:width="2dp"
android:color="#007cea" />
the android:color="#007cea" defines which color you want to give as border
I don't think you will find exactly what you want.
If it was drawable possibly you could use layer-list option.
But it won't work with Imageview.