I want to show edit text box with two sides. so, for that i need to create a rectangle shape with two sides. PLease help some one.
create a drawable under drawable folder and add the belwow contents (border.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#color/black" />
<stroke android:width="1dip" android:color="#color/white"/>
</shape>
Now set the Background of the EditText to this draw able like :
android:background="#drawable/border"
I think the best way to do this is to create a 9-patch in PhotoShop with required border sides... there are also several other ways... depends on your design.
Related
I am trying to achieve this layout. The upper part is a bit dark and it decreases as we move down making it complete transparent. I tried a couple of gradient variations but didn't get the desired results. Does anybody have idea of how to achieve this. Is it gradient or shadow ?
Create a gradient file and use this code you can increase or decrease transparency as you want
layout-->new file-->layout resource file--> give any name
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient android:startColor="#B71A1A1A"
android:angle="270"
android:centerColor="#00FFFFFF"
android:endColor="#00FFFFFF"/>
</shape>
</item>
</selector>
I want to create something like this images and i have a lot of drawables like this one. Please help. thanks
enter image description here
You can use below code for making border :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#color/white"/>
<stroke
android:width="1dp"
android:color="#color/app_color"/>
<corners
android:radius="#dimen/dp_10"/>
</shape>
And use imageView for TopLeft and BottomRigth corners. For making rounded shape of image you may also use cardView.
I am trying to get a glow effect like the background for edittext
I tried doing it but the background is not as much effective as the image
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#68F30606"/>
<corners android:radius="10dp" />
</shape>
</item>
<item
android:left="1.7dp"
android:right="1.7dp"
android:top="1.7dp"
android:bottom="1.7dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="10dp" />
</shape>
</item>
</layer-list>
Can someone help me to solve this mystery?
Then you will need to use the old-technique(kind of) of 9-Patch Drawing. I used to do it too. Examples are scarce because they are big, but there is documentation.
Documentation: https://developer.android.com/studio/write/draw9patch.
Also, if this helps you can check this too: Outer glow in edittext
To use the 9-Patch images in Xml to this (remember this is after you have created the 9-Patch Images):
Reference the drawable with the name but don't include .9.png (auto-complete in eclipse will take care of this)
Make sure you only have 1 image under the main /drawable folder (not a version for each dpi folder)
The image must be specified using :background, not :src (this got me stuck for a while)
android:background="#drawable/splash_logo"
Make sure the image and layout that contains it are using:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Credit To: Creating & Using 9-patch images in Android
Also, check this website out, it contains a lot of useful examples that the documentation doesn't provide:
https://tekeye.uk/android/examples/ui/android-9-patch-image-files
I am struck at this problem of creating the UI in android. I need a xml-based solution to this problem. I don't want to use any SVG or PNG image to achieve the solution. Is there any way to achieve this of view in android.
You should be using a <layer-list> element of xml to draw such a UI.
Following code will be used to create oval shape:
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#AAAAAA"></solid>
<size android:height="100dp"
android:width="60dp">
</size>
This leads to the following shape:
Once you know how to draw an oval shape using xml. Now next step for you is to learn how to use <layer-list> to achieve desired output. To learn using <layer-list> you can follow this tutorial.
By creating a new drawable file which will describe the look of the widget you want to draw,more or less.You can then set it as background for which widget you want to change the original look of. I would recommend starting with rectangle if you want to achieve the shape shown in your question. the drawable file will look something like this:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#000"/>
<corners android:radius="150dp"/> <!-- The value here should specify How much ovally you want shape be -->
</shape>
and then assigning the background of the widget to this drawable should do the trick, something like this:
<LinearLayout
android:background="#drawable/oval">
Hope this was helpful :D
I want to create a composite view with corners that looks like this:
How it this possible in Android?
If someone have the same problem, best way is use 9.png drawables. In xml it's not possible.
You can achieve that with using <vector in a custom drawable file, here invert_shape.xml:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="200dp"
android:viewportWidth="400"
android:viewportHeight="400">
<path
android:pathData="M3.146,256.500 L3.146,73.449 C41.770,72.388 72.757,41.041 72.757,2.500 L271.500,2.500 L271.500,256.500 L3.146,256.500 Z"
android:fillColor="#eeffcc"
android:strokeColor="#000000"
android:strokeWidth="5"/>
</vector>
After that you need to set this drawable as android:background of your LinearLayout in your activity_main.xml like this:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/linear_layout"
android:background="#drawable/invert_shape"
android:layout_centerInParent="true"
android:orientation="horizontal" />
The result:
You may asked yourself how to achieve the android:path in your <vector, I used a simple solution for that. You can use programs like Photoshop or Illustrator and create your shape there in a layer. If you have done that, right click on your layer and select "Copy SVG". Now you copied the shape, paste it in your drawable (here invert_shape.xml) in Android Studio and you will get parameters like android:path and android:stroke of your photoshop shape. Get rid of the unnecessary paramteres and make sure you use the right attributes in the XML itself. Now, there's no end for your creativity. Cheers! :)
You can able to give the OneSide Corner with set the below frame as background to the layout.
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dip"
/>
<solid
android:color="#3D2A1D"/>
<corners
android:radius="20sp"
android:topRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"/>
</shape>
I am not sure with the -ve border radios.