I'm trying to make the edittext background just a straight line instead of usual. I used custom drawable shape for that. But the line is getting added in the middle of the edittext instead of bottom as the regular edittext line. Also when I press enter, it doesn't remain below the cursor as it should be. Is there any good way to do this?
Custom Drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#FA58AC"
android:width="1dp"/>
</shape>
use this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape>
<solid android:color="#android:color/white" />
<stroke
android:width="1dp"
android:color="#android:color/holo_green_light" />
</shape>
</item>
</layer-list>
I think It will be helpful for you.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
// Your line color
<solid android:color="#android:color/black" />
</shape>
</item>
<item android:bottom="1dp">
<shape android:shape="rectangle">
// Your background color
<solid android:color="#android:color/white" />
</shape>
</item>
</layer-list>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Name"
android:textSize="10sp"
android:textColor="#color/color_black_light"
android:paddingLeft="10dp"
android:layout_marginTop="10dp" />
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:layout_marginTop="-10dp"
android:padding="10dp"
android:hint="Name"
android:inputType="text"
android:textColor="#color/black"
android:textColorHint="#color/color_black_light"
android:textCursorDrawable="#null" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/edittext_line_color" />
Related
I've migrated my project to AndroidX. My MainActivity extend FragmentActivity my first SwitchCompat looks all white, it doesn't have any color at all when I first time come to that screen. SwitchCompat is white. All other SwitchCompact under it are with correct color. If I press back and come again to that screen, my first SwitchCompact receive correct color and looks fine.
If I change that my MainActivty extend AppCompactActivity, then everything is ok when I first time reach that screen. Does anyone know where is problem here because before migration my MainActivity also extend FragmentActivity and everything was fine.
My xml code is the same in the both case:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".BlankFragment">
<androidx.appcompat.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<androidx.appcompat.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
I didn`t go deep why this problem occurs when you extend FragmentActivity. but to show appropriate colors on the action event of "SwitchCompat" can achievable by using custom track and thumb.
your switch button
<androidx.appcompat.widget.SwitchCompat
android:id="#+id/sw_autoplay"
android:layout_width="44dp"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:textOff=""
android:textOn=""
android:theme="#style/SwitchButtonTheme"
android:thumb="#drawable/thumb"
app:track="#drawable/track" />
thumb
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false">
<shape android:shape="oval">
<solid android:color="#ffffff" />
<size android:width="20dp" android:height="20dp" />
<stroke android:width=".5dp" android:color="#A4A0A0" />
</shape>
</item>
<item android:state_checked="true">
<shape android:shape="oval">
<solid android:color="#ffffff" />
<size android:width="20dp" android:height="20dp" />
<stroke android:width=".5dp" android:color="#57F47F" />
</shape>
</item>
track
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false">
<shape android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="#ffffff" />
<stroke android:width=".3dp" android:color="#A4A0A0" />
<size android:height="20dp" />
</shape>
</item>
<item android:state_checked="true">
<shape android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="#57F47F" />
<stroke android:width=".3dp" android:color="#A4A0A0" />
<size android:height="20dp" />
</shape>
</item>
It`s just for when you want you to use "FragmentActivity".
I want to add shadow to my text view . I found solutions for adding gradients and one other solution which suggested creating a duplicate text view with a lighter shade at the back of the original textView to give a shadow effect. But i want to have a real shadow effect.
This is what i tried .I created an xml file rounded_corner.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="#33000000"
android:dashWidth="3dp"
/>
<solid android:color="#000000" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:radius="10dp"
/>
</shape>
I added elevation and translationz but its not showing shadow in the output
<TextView
android:background="#drawable/rounded_corners"
android:layout_width="260dp"
android:layout_height="70dp"
android:textSize="50sp"
android:text="Welcome User"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:textColor="#000000"
android:elevation="50dp"
android:translationZ="10dp"
android:id="#+id/welcome"/>
I assume that you want to put the shadow on the TextView and not on the text itself. The you can make a layer-list inside your rounded corner drawable file like this:
<?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/black" />
<corners android:radius="3dp" />
</shape>
</item>
<item android:bottom="2dp" android:right="2dp">
<shape android:shape="rectangle">
<solid android:color="#282828" />
<stroke android:width="1dp" android:color="#302f2f" />
</shape>
</item>
</layer-list>
If you put the drawable as background of your TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_corner"
the output will link like this:
Just pu this on your TextView XML for shadow on the text:
android:shadowColor="#android:color/holo_purple"
android:shadowDx="10"
android:shadowDy="10"
android:shadowRadius="5"
you can edit with your preferences.
And create a Drawable file for shadow in all input, more or less like this one:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Bottom 2dp Shadow -->
<item>
<shape android:shape="rectangle" >
<solid android:color="#d8d8d8" />
</shape>
</item>
<!-- White Top color -->
<item android:bottom="4px" android:left="0px" android:right="4px" android:top="0px">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
You can use the shadow XML attributes.
android:shadowColor="#000"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="50"
For more info check this link, https://developer.android.com/reference/android/widget/TextView.html#attr_android:shadowColor
I have created a custom circular button using the following :
<Button
android:id ="#+id/StartButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:background="#drawable/button_bg_round"
android:padding="15dp"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="#ffffff"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
Here button_bg_round is defined as below :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:color="#ffffff" android:width="5dp" />
<solid android:color="#3aeaee"/>
<size android:width="200dp" android:height="200dp"/>
</shape>
</item>
</selector>
Now, I want to add a circular ripple/pulse effect/animation when the button is clicked. I tried to look for a possible solution on google and SO but couldn't find any related to such a button. Any help would be much appreciated.
You can make you drawable like this:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#color/colorAccent"
tools:targetApi="lollipop"> <!-- ripple effect color -->
<item android:id="#android:id/background">
<shape android:shape="oval">
<stroke android:color="#ffffff" android:width="5dp" />
<solid android:color="#3aeaee"/>
<size android:width="200dp" android:height="200dp"/>
</shape>
</item>
</ripple>
where android:color inside ripple is the color of the effect.
I custom my layout by using layer-list xml in Android. But, I done for layer-list and see exactly what i want to custom. But, when I apply in my layout, it show not exactly what i want, I don't know why.Help me, please!
This is my layer-list.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size
android:width="#dimen/dp35"
android:height="#dimen/dp35" />
<solid android:color="#color/colorAccent" />
</shape>
</item>
<item android:right="12dp"
android:top="#dimen/dp20"
android:bottom="-5dp">
<rotate
android:fromDegrees="25">
<shape android:shape="rectangle">
<solid android:color="#color/colorAccent" />
</shape>
</rotate>
</item>
<item android:left="12.5dp"
android:top="#dimen/dp20"
android:bottom="-5dp">
<rotate
android:fromDegrees="-25">
<shape android:shape="rectangle">
<solid android:color="#color/colorAccent" />
</shape>
</rotate>
</item>
Preview 1
My layout using layer-list.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/bg_sale_off"
android:text="Textview"
android:layout_centerInParent="true" />
</RelativeLayout>
Preview 2 ( without triangle at bottom)
you can try
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_sale_off"
android:text="Textview"
android:layout_centerInParent="true" />
</RelativeLayout>
this is my code below which show dash line on center of textview i want to show below the textview like this:
How can I change this to show below the textview dash line
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/apprentTemp"
android:textColor="#000000"
android:background="#drawable/dotted"
android:paddingLeft="10dp"
android:gravity="left"/>
<TextView
android:id="#+id/localTime"
android:textColor="#000000"
android:background="#drawable/dotted"
android:gravity="center"/>
</TableRow>
<---- dashed.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#000000"
android:dashWidth="5px"
android:dashGap="5px" />
</shape>
use
android:drawableBottom="#drawable/dotted"
instead
android:background="#drawable/dotted"
EDIT:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:left="-5dp"
android:right="-5dp"
android:top="-5dp">
<shape
android:shape="rectangle">
<stroke
android:width="1dp"
android:dashGap="5dp"
android:dashWidth="5dp"
android:color="#android:color/black" />
</shape>
</item>
</layer-list>
Try this
dashed.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:dashGap="2dip"
android:dashWidth="2dip"
android:color="#android:color/black" />
<size android:width="60dp"
android:height="6dp"/>
</shape>
then use
android:drawableBottom="#drawable/dashed"
in your TextView
instead of
android:background="#drawable/dotted"
Output:
This is how i did it.Little modifications and worked.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:gravity="center_vertical"
>
<shape
android:shape="line">
<stroke
android:width="1dp"
android:dashGap="0dp"
android:dashWidth="5dp"
android:color="#color/statusLight" />
</shape>
</item>
Just add android:dashGap to whatever value you desire.
If you want to show the dashed line in the center of the view then use the below code. like -------- Or continue with ----------
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:left="-5dp"
android:right="-5dp"
android:gravity="center_vertical">
<shape
android:shape="line">
<stroke
android:width="1dp"
android:dashGap="2dp"
android:dashWidth="5dp"
android:color="#android:color/darker_gray" />
</shape>
</item>
Try this
<TextView
android:id="#+id/total"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="TextView"
android:drawableBottom="#drawable/dividerline"/>
Make one xml as below
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<size
android:height="1dp"
android:width="70dp" />
<solid android:color="#android:color/black" />
</shape>