Custom background for Text View Using Xml drawable file - android

I want to make a textview background like in the screenshot. I have a xml file that can make rectangular background like in the screenshot but i am not able to do that below corner styling. I dont know what thing can change this.
Here is my xml file that can give a rectangular background to my textview.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="#color/orange" />
<solid android:color="#color/orange" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:radius="5dp" />
</shape>

Your best bet here would be to make a nine-patch image. Roman Nurik has made a really nice nine-patch generator that you can use. Then you just set the image as the background and it will stretch like you think it should.

Related

How to make 3d effect using gradient android

I'm trying to add 3d effect as background of TableRow using gradient, is there a way to make it appear like a stair 3D effectlike that:
And wanna my text appear like a box placed on each stair.
Currently i'm using:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#77F3AE1B"
android:centerColor="#77F3AE1B"
android:endColor="#77AA893C"
android:angle="270"/>
<padding android:left="4dp"
android:right="4dp" />
<corners android:radius="4dp" />
</shape>
but don't look really as 3d effect, i've try to use image background but have lots of problems bcs of screens dimentions and orientation!

Setting no border on Android Drawable defined in XML

I'm trying to define a background drawable in XML that will make the background have a 1dp grey border on the left. The XML I'm using is:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00FFFFFF" />
<stroke android:width="1dp" android:color="#CCCCCC" />
<padding android:left="1dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
In the screenshot below you can see that it's actually putting a 1dp border around the entire view (the "Recent Lessons" area):
Can someone explain to me what I've done wrong here?
I think that you may have confused padding and stroke. The 1dp stroke you are adding is the border you see around the shape - not the padding. Try following these examples. For more about LayerList see the android docs (LayerList section). Basically, it boils down to multiple drawables as one.

A beautiful imageview frame and an animation

I'm searching over the Internet a beautiful frame/border to insert for an image in an imageview....i'm not able to find nothing good.
Now I have this code that insert just a black border, but I would like something more impactive and more beautiful.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="3dp" android:color="#000000" />
<padding android:left="3dp" android:top="3dp" android:right="3dp"
android:bottom="1dp" />
</shape>
Moreover I would like to implement an animation over this image for example when touched that something happen, like that some information happear or the image increases it size. Can someone suggest me some good idea to implement these two things with some good code or some link!!!
You can add corners tag to give it a look of rounded frame.

Can I get a hold of Button Location Data in my Android Application

In my application, I'm (still) trying to manipulate my Button Views to look the way I want. I'd like to attempt an experiment where I'll draw an Android Rect or RectF in the same location as the (transparent) button to highlight it's appearance.
However, I can't figure out how to get my mitts on that information. The buttons in question are defined in XML, in a Linear Layout, but something inside my Android has to know their sizes and locations. Right?
Any suggestions?
Thanks, R.
You should be able to set a background of the button to a custom xml drawable with the drawable containing only stroke element around the edge.
You will need to create this custom drawable: it would be just a few lines of XML.
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" android:color="#CCCCCC" />
<corners android:radius="10dp" />
</shape>
Edit: updated to include rounded corners.
This answer is a combination of my poking around and Aleks' suggestion to use a custom drawable. Ultimately, my custom drawable needed more than three lines, but it's still not very big:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="#android:color/black"
android:endColor="#android:color/black" />
<stroke
android:width="1dp"
android:color="#cccccc" />
<corners
android:radius="5dp" />
<padding
android:left="4dp"
android:top="2dp"
android:right="4dp"
android:bottom="2dp" />
</shape>
</item>
</selector>
I needed to add all of the other detail to get the custom button to work the way I wanted -- and I'm probably not done, but if anybody is interested, this works pretty well...

How can I build such button?

I need to implement such button for my Android app. It would be great to do this without using full image as button.
I've done almost the same button using <shape> with <gradient>. The only thing I need is to add bottom blue button shadow and include image.
Is it possible?
Thanks in advance.
You can do this by combining Shape Drawables inside a Layered Drawable. To do so, you'll have 3 xml files as below:
button.xml (the one you already have i guess)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="16dp" />
<gradient
android:angle="270"
android:centerColor="#FFFFFF"
android:endColor="#CAEBF8"
android:startColor="#FFFFFF"
android:type="linear" />
<padding
android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp" />
<stroke
android:width="2dp"
android:color="#FFFFFF" />
</shape>
button_bg.xml (to add the blue border below the button)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="16dp" />
<solid android:color="#6FC8F1" />
</shape>
layered_button.xml (to combine the previous xml, and the drawable to use as background on your button)
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/button_bg"/>
<item
android:bottom="2dp"
android:drawable="#drawable/button"/>
</layer-list>
You'll find more information on the Layer List in the Drawables Documentation
Make your button's android:background attribute to point your desired image. Create your image with the text and the little person icon. It's not possible to put a text and an image at the same time inside a button.
For the blue shadow, you can either include it in your image or achieve the same result with the gradient attribute as you already said in your question.
For the image, you should use
android:drawableRight
As for the shadow I'm not sure how this is achieved.

Categories

Resources