Android Drawable Horizontal Line - android

Is it possible to make line to be like this with xml? or there's some way to do that..?
I already made some drawable with shape but it's not really like i want
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
<stroke
android:width="0.8dp"
android:color="#color/colorPrimaryDark" />
<solid android:color="#android:color/transparent" />
</shape>

We can create a drawable file also for this. May be helpful for someone.
Drawable file:
<?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="#android:color/white" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<stroke
android:width="5dp"
android:color="#android:color/holo_blue_dark" />
<solid android:color="#android:color/white" />
<corners android:radius="20dp" />
</shape>
</item>
<item android:bottom="25dp">
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#android:color/white" />
<solid android:color="#android:color/white" />
</shape>
</item>
</layer-list>
Result :

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="-5dp"
android:insetRight="-5dp"
android:insetTop="-10dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/transparent" />
<stroke
android:width="3dp"
android:color="#color/colorPrimaryDark" />
<corners
android:bottomLeftRadius="25dp"
android:bottomRightRadius="25dp" />
</shape>
</inset>

Try this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#de0b0b" />
<solid android:color="#ffffff" />
<corners android:radius="20dp" />
</shape>
</item>
<item
android:bottom="5dp"
android:top="0dp">
<shape android:shape="rectangle">
<stroke
android:width="10dp"
android:color="#ffffff" />
<solid android:color="#android:color/transparent" />
<corners android:radius="20dp" />
</shape>
</item>
</layer-list>
USE like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:gravity="center"
android:background="#ffffff"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/test"
android:text="Nilesh"
android:gravity="center"
android:layout_margin="#dimen/_5sdp"
android:padding="#dimen/_5sdp">
</TextView>
</LinearLayout>
OUTPUT
EDIT
Try this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#a032e4" />
<solid android:color="#a032e4" />
<corners android:radius="40dp"/>
</shape>
</item>
<item android:bottom="4dp" >
<shape
android:shape="rectangle">
<stroke android:width="2dp" android:color="#ffffff" />
<solid android:color="#ffffff" />
<corners android:radius="40dp"/>
</shape>
</item>
</layer-list>
USE LIKE THIS
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:gravity="center"
android:background="#FFFFFF"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/test"
android:layout_margin="20dp"
android:padding="10dp"
android:text="Nilesh Rathod"
android:gravity="center" />
</LinearLayout>
OUTPUT

Related

I want to add a shadow of a image button in round shape but cant make it

<ImageButton
android:id="#+id/btn_scan_qr"
android:layout_width="216dp"
android:layout_height="203dp"
android:elevation="10dp"
android:background="#drawable/roundbutton"
android:src="#drawable/ic_power_settings_new_black_24dp"
android:textSize="15dp"
tools:layout_editor_absoluteX="97dp"
tools:layout_editor_absoluteY="225dp"
/>
This is Xml code
<item android:state_pressed="false"
>
<shape android:shape="oval">
<corners android:radius="40dp" />
<solid android:color="#FFFFFF"
/>
<padding
android:bottom="40dp"
android:left="40dp"
android:right="40dp"
android:top="40dp" />
</shape>
</item>
This is Drawable code for shape of oval i want to add shadow of it i have used elevation but it doesnot do anything at all in constrained layout but it does in Linear layout but it is showing shadow in square but i want it in circle
Please try below code
oval shape view with shadow
custom_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list>
<item>
<shape
android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#057F86A6"/>
<padding
android:top="2dp"
android:bottom="2dp"
android:right="2dp"
android:left="2dp"/>
</shape>
</item>
<item>
<shape
android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#107F86A6"/>
<padding
android:top="1.8dp"
android:bottom="1.8dp"
android:right="1.8dp"
android:left="1.8dp"/>
</shape>
</item>
<item>
<shape
android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#207F86A6"/>
<padding
android:top="1.5dp"
android:bottom="1.5dp"
android:right="1.5dp"
android:left="1.5dp"/>
</shape>
</item>
<item>
<shape
android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#357F86A6"/>
<padding
android:top="1.1dp"
android:bottom="1.1dp"
android:right="1.1dp"
android:left="1.1dp"/>
</shape>
</item>
<item>
<shape
android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#457F86A6"/>
<padding
android:top="0.9dp"
android:bottom="0.9dp"
android:right="0.9dp"
android:left="0.9dp"/>
</shape>
</item>
<item>
<shape
android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#507F86A6"/>
<padding
android:top="0.8dp"
android:bottom="0.8dp"
android:right="0.8dp"
android:left="0.8dp"/>
</shape>
</item>
<item>
<shape
android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#607F86A6"/>
<padding
android:top="0.5dp"
android:bottom="0.5dp"
android:right="0.5dp"
android:left="0.5dp"/>
</shape>
</item>
<item>
<shape
android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#fff"/>
</shape>
</item>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="120dp"
android:layout_height="120dp"
android:gravity="center"
android:background="#drawable/custom_button">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
</LinearLayout>
</LinearLayout>

I'm trying to customize a seekbar, but it's not working

I have this image of the seekbar that I want to build:
But my seekbar is looking like this:
My seekbar has no transparency and I can not make it thinner.
How can I do this?
Here are the codes:
Seekbar:
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.75"
android:max="25"
android:min="7"
android:progress="1"
android:splitTrack="false"
android:progressDrawable="#drawable/progress_seek_bar_settings"
android:thumb="#drawable/thumb_seekbar_settins" />
Thumb:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="oval">
<size
android:height="20dp"
android:width="20dp" />
<solid android:color="#color/color_primary_dark" />
</shape>
</item>
</layer-list>
Progress:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<gradient
android:startColor="#color/color_primary"
android:endColor="#color/color_primary"/>
<size
android:width="1dp"
android:height="2dp"
/>
<corners android:radius="3dp" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#color/color_primary"
android:endColor="#color/color_primary" />
<size
android:width="1dp"
android:height="2dp"
/>
<corners android:radius="3dp" />
</shape>
</clip>
</item>
</layer-list>
I need help getting it as close to the first image as possible. Thank you!!
Hello in drawable/progress_seek_bar_settings transform
<item android:id="#android:id/background">
in
<item android:id="#android:id/background"
android:height="3dp"
android:gravity="center_vertical"
>
UPDATE
drawable/thumb_seekbar_settins.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="oval">
<size
android:height="20dp"
android:width="20dp" />
<solid android:color="#ebeb" />
</shape>
</item>
</layer-list>
drawable/progress_seek_bar_settings.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background"
android:height="3dp"
android:gravity="center_vertical"
>
<shape>
<gradient
android:startColor="#ebeb"
android:endColor="#ebeb"/>
<size
android:width="1dp"
android:height="2dp"
/>
<corners android:radius="3dp" />
</shape>
</item>
<item android:id="#android:id/progress"
android:height="3dp"
android:gravity="center_vertical"
>
<clip>
<shape>
<gradient
android:startColor="#ebeb"
android:endColor="#ebeb" />
<size
android:width="1dp"
android:height="2dp"
/>
<corners android:radius="3dp" />
</shape>
</clip>
</item>
</layer-list>
activity
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="40dp"
android:background="#android:color/black"
>
<SeekBar
android:layout_marginTop="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.75"
android:max="100"
android:min="7"
android:progress="1"
android:splitTrack="false"
android:progressDrawable="#drawable/progress_seek_bar_settings"
android:thumb="#drawable/thumb_seekbar_settins" />
</android.support.constraint.ConstraintLayout>
looks like this:

How to draw vertical shape in the centre of XML drawable

How can a vertical line be drawn within an XML drawable when using a layer-list? I declared 3 shapes within the drawable but for some reason it doesn't appear as expected.
<?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="#color/green"/>
</shape>
</item>
<item android:top="0dp" android:left="1dp" android:bottom="0dp" android:right="5dp">
<shape android:shape="rectangle">
<size android:width="3dp"/>
<solid android:color="#android:color/white"/>
</shape>
</item>
<item android:top="0dp" android:left="5dp" android:bottom="0dp" android:right="1dp">
<shape android:shape="rectangle">
<size android:width="3dp"/>
<solid android:color="#android:color/white"/>
</shape>
</item>
</layer-list>
Current result
Expected result
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="16dp"
android:left="15px">
<shape
android:shape="rectangle">
<solid android:color="#color/colorAccent" />/>
<size android:width="5dip" />
<stroke android:color="#color/colorAccent" />
</shape>
</item>
<item
android:width="16dp"
android:left="80px">
<shape
android:shape="rectangle">
<solid android:color="#color/colorAccent" />/>
<size android:width="5dip" />
<stroke android:color="#color/colorAccent" />
</shape>
</item>
<item
android:width="16dp"
android:left="140px">
<shape
android:shape="rectangle">
<solid android:color="#color/colorAccent" />/>
<size android:width="5dip" />
<stroke android:color="#color/colorAccent" />
</shape>
</item>
</layer-list>
Try this solution
drawable/shape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/colorAccent" />/>
<size android:width="5dip" />
<stroke
android:color="#color/colorAccent"
/>
</shape>
Include in the layout file the following
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<View
android:layout_width="15dip"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_horizontal_margin"
android:background="#drawable/shape"></View>
<View
android:layout_width="15dip"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_horizontal_margin"
android:background="#drawable/shape"></View>
<View
android:layout_width="15dip"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_horizontal_margin"
android:background="#drawable/shape"></View>
</LinearLayout>
Change the colors and fix the margins of the layout.

How to implement opposite gradient in android?

I am using this
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="7sp" />
<gradient
android:startColor="#333"
android:centerColor="#ffffff"
android:endColor="#333"
android:angle="90" />
<stroke android:width="1dp" android:color="#FFffffff" />
</shape>
</item>
But this does not give the desired effect.
You can try it this way
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/gradient"
android:orientation="vertical" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/gradient2"
android:orientation="vertical" >
</RelativeLayout>
</RelativeLayout>
Gradient 1
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<corners android:radius="7sp" />
<gradient
android:angle="90"
android:endColor="#D1D1D1"
android:startColor="#000" />
<stroke
android:width="1dp"
android:color="#FFffffff" />
</shape>
</item>
</layer-list>
Gradient 2
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<corners android:radius="7sp" />
<gradient
android:angle="90"
android:endColor="#000"
android:startColor="#D1D1D1" />
<stroke
android:width="1dp"
android:color="#FFffffff" />
</shape>
</item>
</layer-list>
Final Result
Use this instead
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#333"
android:centerColor="#DDD"
android:endColor="#333"
android:angle="90" />
<stroke android:width="1dp" android:color="#FF333333" />
</shape>
</item>
<item android:left="4dp" android:right="4dp" android:top="1dp" android:bottom="1dp">
<shape android:shape="rectangle">
<gradient
android:startColor="#AAA"
android:centerColor="#FFF"
android:endColor="#AAA"
android:angle="90" />
</shape>
</item>
</layer-list>
But it's better to use nine-patch images
Try
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="#4C4C43"
android:centerColor="#B8B894"
android:endColor="#4C4C43"
android:angle="270" />
</shape>
</item>
P.S - change color according to your need
reference- http://www.learn-android-easily.com/2013/06/gradient-drawable-in-android.html
Use :
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:type="linear"
android:centerX="50%"
android:startColor="#FFc0c0c0"
android:centerColor="#FFffffff"
android:endColor="#FF808080"
android:angle="270"/>
</shape>
<corners android:radius="7sp" />

listview border remove when focus

My listview remove his border when focus or long press this way
below is my listview code please help me why border remove when focus???
everything is fine only listview border will remove whenlong presss
i edit my code please check now
<LinearLayout
android:id="#+id/lytContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/layout_border"
android:orientation="vertical" >
<ListView
android:id="#+id/listMainMenu2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dip"
android:fadeScrollbars="true"
android:listSelector="#drawable/listview_selector" />
</LinearLayout>
<-----listview_selector.xml---->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/listviewborder"
android:state_focused="true"/>
<item
android:drawable="#drawable/listview_selector_pressed"
android:state_pressed="true"/>
</selector>
<-----listviewborder.xml----->
<?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="#000000" />
</shape>
</item>
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp">
<shape android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#56768d"
android:startColor="#0a89f1" />
</shape>
</item>
</layer-list>
<------listview_selector_pressed------>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<item android:left="1dp" android:right="1dp" android:top="1dp" android:bottom="1dp"
>
<shape android:shape="rectangle">
<gradient
android:startColor="#0a89f1"
android:endColor="#56768d"
android:angle="90" />
</shape>
</item>
</layer-list>
<-----layoutborder.xml--->
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke
android:width="3dip"
android:color="#B1BCBE" />
<corners android:radius="10dip" />
<padding
android:bottom="0dip"
android:left="0dip"
android:right="0dip"
android:top="0dip" />
</shape>

Categories

Resources