How to give any shape to Views in android
I want following background to textview.
You can create shapes using xml drawables in Android.
https://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
But the background you want is not straightforward using xml. So I recommend creating background using any image editor and set it as background of the textview.
Another approach would be to create vector drawable for the required shape which is supported from android API 21. Here is a good tutorial to create your your own shapes and images
https://medium.com/#ali.muzaffar/understanding-vectordrawable-pathdata-commands-in-android-d56a6054610e
To customize a View you should create a custom view. Create a new class by extending the View class, implement all public constructors and override the onDraw function. When using in the layout file give the full path of the custom view:
<com.example.ownview.MyDrawView
android:id="#+id/myDrawView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Related
I think i mentioned the name of the shape wrong.
I want to make shape like the following image with shadows in Android,
Sample model
So how to make this type of layout in Android .
thanx for the help!!
You should try this one:
https://github.com/Hitomis/CrazyShadow
By drawable you can generate the shape, and by using this library you will be able to add shadow.
Or:
You can use the library itself.
I Just know that we can use fonts for text only by using the TypeFace class. But can anyone please confirm me about images.
I have added all my custom fonts(.ttf) inside asset/fonts folder. Placed some ImageViews in their appropriate place in my app. And trying to use fonts to set images on them.
I have googled for a long time, but unfortunately unable to find any satisfied hint or help.
Can any one please help me to go forward from the current step.
Placed some ImageViews in their appropriate place in my app. And trying to use fonts to set images on them.
ImageView accepts images. Whatever set of pixels or vectors are in a font, they are not images from the standpoint of ImageView. The simplest way to display material from a custom font is through TextView, though you are welcome to implement your own Drawable and attempt to use that with an ImageView, or draw straight to the Canvas (e.g., in a custom widget).
You can use font awesome. Import the android-iconify/1.0.6 jar library from http://repo1.maven.org/maven2/com/joanzapata/android/android-iconify/1.0.6/
and you can use IconTextView
<IconTextView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="10dp"
android:text="{fa-mobile}"
android:textColor="#9fd46c"
android:textSize="30dp"
/>
How to create a custom shape like below image?
Any help would be appreciated.
Make a new class that extends view.
In the onDraw() use moveTo and lineTo to make the exact shape you want.
In your layout, use:
<com.example.yourpackage.YourViewClass android:id...
you should override onDraw() method to create a custom shapes
this page may help you
http://developer.android.com/training/custom-views/custom-drawing.html
You can use this library PathDrawable
PathDrawable is a Drawable that draws simple shapes using Path object.
try this site its generate XML code for Shape
http://angrytools.com/android/button/
I found some code in our project where someone is iterating over the children of a ViewGroup so they can set a custom Java-based drawable as the background. I'd like to clean that up a bit by setting the background drawable in our layout XML files.
Is there a way to specify a Java class to use as the background via the XML layout definition?
I think you can reference the java class by specifying it's full path (i.e. its package).
For instance, com.example.android.yourClass.
After looking around quite a bit I was unable to find a way to do this. I had to specify the background drawable in code.
I'm trying to create a rotating imageView. Looking at this (http://stackoverflow.com/questions/1930963/rotating-a-view-in-android) I know I'll have to override onDraw.
But when I create my own derrived TextView class, how do I use it in my xml layouts?
To use it in your xml layout add the following:
<view class="yourpackage.yourclass.yourview" ...additional parameters... />
note the lowercase "view" or by directly specifying its name
<yourpackage.yourclass.yourview ...additional parameters... />
How to create and access custom components is discussed here
http://developer.android.com/guide/topics/ui/custom-components.html