i want to set text upside of image in button property.
here is my code for it but i get it text is behind of image which property i have to set ?
<RelativeLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="horizontal"
android:background="#drawable/nav_bar">
<Button
android:id="#+id/btnHome"
android:layout_width="60dp"
android:layout_height="70dp"
android:onClick="onHomeClick"
android:text="Home"
android:gravity="bottom|center_horizontal"
android:drawableTop="#drawable/btn_home"
android:background="#null"
android:textColor="#android:color/white"
android:textSize="16sp"
android:paddingBottom="10dp"
android:includeFontPadding="true"
/>
use android:drawableBottom instead of android:drawableTop there.
try this...
<Button
android:id="#+id/btnHome"
android:layout_width="wrapcontent"
android:layout_height="70dp"
android:onClick="onHomeClick"
android:text="Home"
android:gravity="bottom|center_horizontal"
android:drawableBottom="#drawable/btn_home"
android:background="#null"
android:textColor="#android:color/white"
android:textSize="16sp"
android:paddingBottom="10dp"
android:includeFontPadding="true" />
There is problem with your 'layout width and height' that's why your text appears behind the image.
<Button android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onHomeClick"
android:text="Home"
android:gravity="top|center_horizontal"
android:drawableBottom="#drawable/app_icon"
android:textColor="#android:color/white"
android:textSize="16sp"
android:paddingTop="10dp"
></Button>
try this one.instead of specifying width and height better to use wrap_content property.bcoz in future if u want to change the image that will be automatically fix it.
Related
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:background="#ffffff">
<TextView
android:id="#+id/sorttxt"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.995"
android:text="Sort"
android:textSize="17dp"
android:textColor="#000000"
android:background="#25a65b"
android:drawableLeft="#drawable/leftImagesort"
android:gravity="center"
/>
<View
android:layout_width="0dp"
android:layout_height="40dp"
android:background="#color/grey_5"
android:layout_weight="0.01" />
<TextView
android:id="#+id/filtertxt"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.995"
android:text="Sort"
android:textSize="17dp"
android:textColor="#000000"
android:background="#25a65b"
android:drawableLeft="#drawable/leftImagefilter"
android:gravity="center"
/>
I am using above code but wants to remove gap between image and text i have used android:drawableLeft to insert image in textview
right now i am getting output shown in image
Set attribute android:gravity="left" instead of android:gravity="center" in both TextView
If you are using drawable left for showing image and you want to remove gap between image and text then you need to use android:drawablePadding="-20dp". you need to give drawablePadding in minus.
You can use like :
android:drawableLeft="#mipmap/ic_launcher"
android:drawablePadding="-20dp"
set drawablePadding="0dp" and android:gravity="left|center"
I'm trying to make an image fit into the EditText itself using drawableLeft, without any padding or "whitespaces" around it.
This is what the image looks like for now
This is how it should look like
I tried increasing the size of the image itself but it made the EditText expand even more.
Here's the XML file:
<EditText
android:layout_marginTop="6dp"
android:id="#+id/login_password"
android:layout_width="315dp"
android:layout_height="wrap_content"
android:textSize="17dp"
android:textColor="#8d8e8f"
android:hint="Password"
android:drawableLeft="#drawable/sample"
android:singleLine="true"
android:inputType="textPassword"
android:layout_below="#+id/login_name"
android:layout_centerHorizontal="true" />
How can the image fit inside the EditText? Does it something to do about the image itself?
You can try the LinearLayout for it. Means in the LinearLayout , you should put the Editext's drawable image as the background , and than divide it in to three parts,1st part is for the password_image , 2nd one for your EditText and and 3rd last one for is your INVISIBLE View, which prevent , your EditText value to touch at end
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/EDITEXT_DRAWABLE"
android:gravity="center_vertical"
android:padding="5dp"
android:weightSum="2">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:gravity="left|center"
android:src="#drawable/sample" />
<EditText
android:id="#+id/password_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.5"
android:background="#android:color/transparent"
android:ems="10"
android:gravity="center"
android:hint="********"
android:inputType="textPassword"
android:paddingLeft="-10dp"
android:singleLine="true"
android:imeOptions="actionDone"
android:textColor="#android:color/white"
android:textColorHint="#android:color/white" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:layout_weight="0.1"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:src="#drawable/sample"
android:visibility="invisible" /> ///PUT THE VIEW INVIIBLE
</LinearLayout>
Just use a Fram layout it works well use a frame layout and inside it edit text and an image view is created set the background of image view to transperent and gravity to the right or to the left
<FrameLayout
android:layout_width="match_parent"
android:layout_height="25dp">
<EditText
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/border_round"
android:drawableLeft="#color/place_autocomplete_search_text"
android:drawableStart="#drawable/places_ic_search"
android:drawableRight="#drawable/arrowxml">
</EditText>
<ImageView
android:layout_width="25dp"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
android:layout_gravity="right"
android:src="#drawable/searcharrow"
android:layout_height="25dp" />
use this...........
<EditText
android:id="#+id/user_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/editback"
android:drawableLeft="#drawable/useremail"
android:drawablePadding="10dp"
android:hint="#string/user_name"
android:padding="7dp"
android:singleLine="true"
android:textColor="#9291A1"
android:textSize="15sp" />
I am using the EditText with drawableLeft property and set ImageView in Right side for ClearText. My Question is how to put gap between text and Imageview in EditText?
Please help me.
Actually I have Like this,My Screenshot is,
Actually I want to Like this,
Create Gap Between Text and ImageView. How it is Possible?.
My xml file is,
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/edtSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="5dip"
android:drawableLeft="#drawable/search"
android:drawablePadding="10dip"
android:hint="Find"
android:imeOptions="actionNext"
android:inputType="text"
android:singleLine="true" >
</EditText>
<ImageView
android:id="#+id/imgSearchClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/edtSearch"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:contentDescription="#string/app_name"
android:src="#drawable/clear" />
</RelativeLayout>
Okay i got your Question now...you have to use Search view instead of edittext
Here is link:- Check it out
Only this is a solution of your problem
i am using LinearLayout for this
<LinearLayout
android:id="#+id/linear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="#+id/chatText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textMultiLine"
android:padding="8dp" />
<ImageView
android:id="#+id/buttonSend"
android:layout_width="50sp"
android:layout_height="50sp"
android:padding="5dp"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Had the same problem a while ago fixed it with drawablePadding
Hello
Use Linear layout with weight instead of Relative as m showing below:-
<LinearLayout
width
hight
orientation="horizontal">
<EditText
android:id="#+id/edtSearch"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:drawableLeft="#drawable/search"
android:drawablePadding="10dip"
android:hint="Find"
android:imeOptions="actionNext"
android:inputType="text"
android:singleLine="true" >
</EditText>
<ImageView
android:id="#+id/imgSearchClear"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:contentDescription="#string/app_name"
android:src="#drawable/clear" />
</LinearLayout>
if you found any issue regarding this please let me know..i love to help you
or in relative layou you can use drawable padding
Spartacus thanks :)
I can try to implement your code but It Like this,
and I want to Like this,
Set the right padding of EditText to the width of Clear button. Set all the dimension in dimen folder so that it will be compatible with all device sizes.
This is my code:
<TextView
android:id="#+id/error_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:gravity="center"
android:drawableRight="#drawable/error_image"
android:visibility="invisible"
android:textColor="#aa0000"
android:textStyle="bold"
android:textSize="16dp"/>
There is space between image and text and I want reduce this space, how can I do it?
As you had set android:layout_width="match_parent", TextView took all the width so the drawablePadding which you set will not work. So you need to set android:layout_width="wrap_content".
Try following code :
<TextView
android:id="#+id/error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="0dp"
android:layout_marginBottom="2dp"
android:drawableRight="#drawable/ic_launcher"
android:gravity="center"
android:textColor="#aa0000"
android:textSize="16dp"
android:text="adsfasdfa"
android:textStyle="bold"
android:visibility="invisible" />
You should set the property android:drawablePadding="0dp"
Or in your java code, call textView.setCompoundDrawablePadding(0);
I want to put a text exactly in the center of its containing box, and in preview that's OK, but in emulator it has a problem.
<TextView
android:id="#+id/textView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#000"
android:gravity="center"
android:text="E"
android:textAllCaps="true"
android:textColor="#FFF"
android:textSize="75dp"
android:textStyle="bold" />
Any suggestions how to do that?
Add android:includeFontPadding=false to your TextView
<TextView
android:id="#+id/textView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#000"
android:gravity="center"
android:includeFontPadding=false
android:text="E"
android:textAllCaps="true"
android:textColor="#FFF"
android:textSize="75dp"
android:textStyle="bold" />
http://developer.android.com/reference/android/widget/TextView.html#attr_android:includeFontPadding
Fonts have an inherent padding in them and this is what seems to be causing the problem.
Potentially it's just a bug in the preview why it's not showing up there but is in the emulator.
Change layout_height to wrap_content