Issue
I have custom EditText
drawable:
edit_text_selector
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/edit_text_background_on" />
<item android:state_focused="false" android:drawable="@drawable/edit_text_background_off" />
</selector>
edit_text_background_on
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="@color/main_color" />
</shape>
</item>
<item
android:bottom="1.5dp"
android:left="1.5dp"
android:right="1.5dp">
<shape>
<solid android:color="@color/background_color" />
</shape>
</item>
<item
android:bottom="5.0dp" >
<shape>
<solid android:color="@color/background_color" />
</shape>
</item>
</layer-list>
edit_text_background_off
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="@color/edittext_off_color" />
</shape>
</item>
<item
android:bottom="1.5dp"
android:left="1.5dp"
android:right="1.5dp">
<shape>
<solid android:color="@color/background_color" />
</shape>
</item>
<item android:bottom="5.0dp">
<shape>
<solid android:color="@color/background_color" />
</shape>
</item>
</layer-list>
I want to have padding in EditText so that the text is not in the most left position of EditText.
Tried to use this but doesn't work.
<inset android:insetLeft="6dip"/>
How can I add padding in EditText drawable? I don't want to put it in every EditText in my XML layout.
Solution
I found this .. Hope it will help. This is the logic . you need to customize it.
This is main Layout where you can add edittext
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#eee">
<!-- Input Group -->
<EditText style="@style/Widget.Group.Top" />
<EditText style="@style/Widget.Group" />
<EditText style="@style/Widget.Group.Bottom" />
<!-- Single item -->
<EditText style="@style/Widget.Group.Single" />
</LinearLayout>
and add some style in you style file like this
<style name="Widget.Group" parent="@android:style/Widget">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">46dp</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:layout_marginRight">10dp</item>
<item name="android:layout_marginTop">-1dp</item> <!-- Ensures we don't get a 2 dp top stroke -->
<item name="android:padding">4dp</item>
<!--<item name="android:background">@drawable/bg_input_group</item>-->
</style>
<style name="Widget.Group.Top">
<item name="android:layout_marginTop">10dp</item>
<!--<item name="android:background">@drawable/bg_input_group_top</item>-->
</style>
<style name="Widget.Group.Bottom">
<item name="android:layout_marginTop">20dp</item>
<!--<item name="android:background">@drawable/bg_input_group_bottom</item>-->
</style>
<style name="Widget.Group.Single" parent="Widget.Group.Top">
<!--<item name="android:background">@drawable/bg_input_group_single</item>-->
</style>
For more details click here .
Answered By - Tanim reja
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.