How to change editText hint postion - android

Can I change "hint" and text position (to rise it to the center)
My xml as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layoutTopBlue"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:background="#4285F4"
android:layout_below="#id/layoutTopBlack"
>
<EditText
android:id="#+id/editText1"
android:layout_gravity="center"
android:text=''
android:hint="my hint"
android:textColorHint="#FFFFFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="#drawable/edit"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/editText1"
android:src="#drawable/search"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_alignRight="#+id/editText1"
android:src="#drawable/cross"
/>
</RelativeLayout>
Or maybe it is possible to do something with drawable editText:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape >
<solid android:color="#color/editBorder" />
</shape>
</item>
<!-- main color -->
<item android:bottom="1.5dp"
android:left="1.5dp"
android:right="1.5dp">
<shape >
<solid android:color="#color/editBackground" />
</shape>
</item>
<!-- draw another block to cut-off the left and right bars -->
<item android:bottom="5.0dp">
<shape >
<solid android:color="#color/editBackground" />
</shape>
</item>
</layer-list>
Any ideas please?
Thanks!

anyone can use
android:gravity="center|center_horizontal|center_vertical|top"

1) hind text in left of the edittext
<EditText
android:gravity="left"
/>
2) hind text in center of the edittext
<EditText
android:gravity="center"
/>
3) hind text in right of the edittext
<EditText
android:gravity="right"
/>

If you need to change the position of edit text.
In Graphical layout :- place the cursor in text(hint) and right click ,Layout height -> other -> then set the custom layout attribute value( example :50dp)
I think this will work .To rise it in center you can change this value to 30dp or 50dp.
or
Change this line in Edit text :-
android:layout_height="wrap_content" to android:layout_height="50dp"

Related

android: How to set margin/padding between EditText custom background and InputTextLayout Label?

Well I want to set margin/padding between EditText and InputTextLayout Label on Pressed State.
Here's my image of - desired design
Main Xml code - `
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:src="#drawable/headphones_3" />
<android.support.design.widget.TextInputLayout
android:id="#+id/textLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:visibility="gone"
app:theme="#style/TextLabel">
<EditText
android:id="#+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/password_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:theme="#style/TextLabel">
<EditText
android:id="#+id/input_password"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#drawable/edit_text_style"
android:drawablePadding="#dimen/floating_hint_margin"
android:hint="Password"
android:inputType="textPassword"
android:paddingLeft="#dimen/floating_hint_margin" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
`
Though right now i applied custom theme only to 'Password" TextInputLayout.!
Here is the code of edit_text_style
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- focused state -->
<item android:state_focused="true">
<shape android:shape="rectangle">
<solid android:color="#80FFFFFF" />
<stroke android:width=".5dp" android:color="#color/colorPrimary" />
<corners android:radius="6dp" />
</shape>
</item>
<!-- normal state -->
<item>
<shape>
<solid android:color="#android:color/transparent" />
<stroke android:width="2dp" android:color="#color/colorPrimary" />
<corners android:radius="22dp" />
</shape>
</item>
The result which I got - Resulted Image
As you can see the Label goes up to cursor and there's no padding between Label and EditText background.
And how to set Label to where the EditText Background starts ( as it's on top of cursor right now )?
( Sorry for my bad english )
UPDATE : Let me explain you - See those images again.! What i want to set padding between TextInputLayout label ( which is password here when you focus it ). What you guys said was creating padding between custom drawable ( which is edit_text_style here ) cursor and Label, but i want padding between the drawable I added and Label ( password text which appear when it's on focused state ) & Also want to set Label position as it's goes upward to cursor start.!
#Ansh.... You are set the drawable to your TextInputLayout and take padding to both edittext and TextInputLayout.....
In your way it's is not work well.... if you want to do like that you want with textinputlayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:src="#mipmap/ic_launcher" />
<android.support.design.widget.TextInputLayout
android:id="#+id/textLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:padding="10dp"
android:background="#drawable/edit_text_style"
android:visibility="visible">
<EditText
android:id="#+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:hint="Email"
android:inputType="textEmailAddress"
android:padding="10dp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/password_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_text_style"
android:padding="10dp"
android:visibility="visible">
<EditText
android:id="#+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:padding="10dp"
android:hint="Password"
android:inputType="textPassword"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
And also in your drawable take only one rectangle or Rounded for better View
You can apply a custom style to your EditText (the ones where you need to have a padding onPressedState) :
<EditText
android:id="#+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress" />
And the style :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="#drawable/next_white">
<inset android:insetLeft=""YOUR_PADDING_IN_DP dp"/>
Source : android:drawableLeft margin and/or padding
For the margin, it isn't possible to do it with drawable, but you can still define an animation which will do the trick :
In res/anim, create a margin_animation.xml :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/accelerate_interpolator">
<translate android:fromYDelta="0" android:toYDelta="100%" />
</set>
Source : In Android, is it possible to set the margin from the drawable?

android spinner ripple effect on target 19

Hello all I want to do like below image
for that i have done is, I made a custom view for row items
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
<com.andexert.library.RippleView
android:id="#+id/more1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/tvspinnerlist"
android:text="Spinner List"
android:singleLine="false"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="4dp"
android:fontFamily="sans-serif-medium"
android:textColor="#color/black"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginRight="5dp"
android:layout_marginLeft="3dp"
android:ellipsize="marquee" />
</com.andexert.library.RippleView>
</RelativeLayout>
and this is my spinner
<com.andexert.library.RippleView
android:id="#+id/more1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Spinner
android:id="#+id/spnOperator"
style="?android:label"
android:descendantFocusability="blocksDescendants"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.17" />
</com.andexert.library.RippleView>
For this i am facing 2 problems...
on click on right hand side button only(triangle btn) spinners opens(not opening on spinner click)
spinner does not close on item selection
Thanks,
You basically have two ways:
Create RippleDrawable in res/values-v21/ and set that to be the background on the Spinner spinner.setBackgroundResource(R.drawable.spinner_background);.
Do this using Theme. Define the spinner like this: (somewhere in you activity.xml)
ripple_background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<ripple android:color="?android:attr/colorControlHighlight">
<item>
<shape>
<solid android:color="#android:color/white" />
</shape>
</item>
</ripple>
</item>
</selector>

Card Interface: Can't fit contents and text is clipped

I'm making an app with it's contents inside card-like views but I am having a couple of problems:
I can't get the label line (the blue line) to move away from the card text. I've tried both padding and margin (on both line imageview and textview from text) and nothing seems to work here.
The bottom part of the card title is getting cropped because of the line spacing. How can I fix this and keep the line spacing?
Check this screenshot for better understanding: http://imgur.com/qsoCFrB
Here's the code to the card background and the interface itself:
card_bg:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="1dp"/>
<solid android:color="#bdbdbd" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="2dp" />
<solid android:color="#android:color/white" />
<padding android:bottom="6dp"
android:left="6dp"
android:right="6dp"
android:top="4dp" />
</shape>
</item>
</layer-list>
main acitivity:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:background="#drawable/card_bg" >
<ImageView
android:id="#+id/iconView0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="6dp"
android:src="#drawable/icon_example" />
<ImageView
android:id="#+id/labelSource0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/cardText0001"
android:layout_marginTop="4dp"
android:background="#drawable/card_label" />
<TextView
android:id="#+id/cardTitle0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/cardText0001"
android:layout_toRightOf="#+id/iconView0001"
android:fontFamily="sans-serif-condensed"
android:maxLines="2"
android:paddingLeft="4dp"
android:lineSpacingExtra="-6dp"
android:text="#string/card_title_002"
android:textColor="#717171"
android:textSize="16sp" />
<TextView
android:id="#+id/cardText0001"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/iconView0001"
android:fontFamily="sans-serif"
android:layout_marginTop="4dp"
android:maxLines="1"
android:text="#string/card_desc_002"
android:textColor="#acacac"
android:textSize="12sp" />
</RelativeLayout>
</FrameLayout>
Thanks in advance.
this is the creator of the Gist on GitHub!
Have you tried increasing padding on the RelativeLayout, perhaps that could fix the problem? Or even on the TextView element?
Try doing that and see what the results are.
EDIT: Also, why is there negative line spacing within the Text View?
DOUBLE EDIT: So what was happening is that your layout_alignBottom in the linkTitle TextView was shorter than the height of two lines of text, therefore it was cropping the title to limit the height of the TextView to that of the FavIcon ImageView. Removing this property fixes the issue.
Similar issue goes for the label shape, that alignBottom is what's messing it up.
Change layout_alignBottom to layout_below and then padding/margin should affect the position as you please.
Here is the updated version of your code that should remedy your issues:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linkCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ccc" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:background="#drawable/card_bg">
<TextView
android:id="#+id/linkTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/faviconView0001"
android:padding="4dp"
android:maxLines="2"
android:text="#string/link_title_001"
android:textColor="#717171"
android:textSize="17sp" />
<TextView
android:id="#+id/linkDesc0001"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linkTitle"
android:paddingTop="6dp"
android:paddingBottom="9dp"
android:fontFamily="sans-serif"
android:maxLines="1"
android:text="#string/link_desc_001"
android:textColor="#acacac"
android:textSize="13sp" />
<ImageView
android:id="#+id/faviconView0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="6dp"
android:layout_alignParentLeft="true"
android:src="#drawable/favicon_example" />
<View
android:layout_height="0dp"
android:layout_width="fill_parent"
/>
<ImageView
android:id="#+id/labelSource0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linkDesc0001"
android:background="#drawable/card_label" />
</RelativeLayout>
</FrameLayout>
I hope that all of this helps!

Trying to space items in a ListView while using adapter and drawable. Margin is not working

I am trying to have a listview where items have rounded corners and the items are spaced out from each other. This is done using a custom ArrayAdapter.
MyCustomAdapter arrAdapter = new MyCustomAdapter();
setListAdapter(arrAdapter);
I am using a drawable image to round the corners
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="10dp" />
<gradient
android:angle="90"
android:endColor="#993333"
android:startColor="#ffffff"
android:type="sweep" />
<solid android:color="#ffffff" />
<stroke
android:width="1dp"
android:color="#000000" />
</shape>
and setting it in the layout as background to the top most container - the LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="#drawable/square"
android:orientation="horizontal" >
<TextView
android:id="#+id/routeTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/circle"
android:padding="10dp"
android:text="text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="some text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="14sp" />
<TextView
android:id="#+id/stopD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"
android:text="(text)"
android:textColor="#777777"
android:textSize="10sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/nextTT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="9dp"
android:paddingTop="5dp"
android:text="text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="14sp" />
<TextView
android:id="#+id/moreTT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/nextTrainTime"
android:paddingBottom="5dp"
android:text="text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
For some reason in the graphical display I am able to see that single element exactly as I want it - with margins all around (I also want it to move away from the edges of the screen left and right).
But when I run this and let the adapter do its job I am getting a list of items, touching the sides of the screen and no space between them apart forma single line which is used to separate the items on a normal list.
Anyone have a clue how to make it behave?! I have search far and wide.
Thanks for your help
The space between your item and widescreen can be done with:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="10dp"
android:right="10dp"
android:top="10dp"
android:bottom="10dp">
<shape android:shape="rectangle">...</shape>
</item>
In my case I used android:divider and android:dividerHeight on a ListView block to seperate each element of a ListView, and the left-right space with the android:left android:right properties.
The post where I got the info was this

Android include shape in xml

Hi have shape and am trying to include this in my layout but it doesn't show?
This is my shape xml "damage.xml"
<shape xmlns:android="http://schemas.android.com/apk/res/android"
shape="rectangle">
<solid color="#ff0000" />
<stroke width="3dp" color="#ff0000" />
And this is my I thought I needed to include the Shape in the layout.
<?xml version="1.0" encoding="utf-8"?>
<View android:id="#+id/damage" android:background="#layout/damage"
android:layout_width="5dip" android:layout_height="wrap_content">
</View>
<ImageView android:id="#+id/icon" android:layout_width="60px"
android:layout_height="60px" android:layout_marginRight="6dip"
android:src="#drawable/placeholder" />
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:padding="6dip">
<TextView android:layout_width="fill_parent" android:id="#+id/title"
android:layout_height="wrap_content" android:text="Item Name"
android:textStyle="bold" android:singleLine="true" android:textSize="16sp" />
<ImageView android:id="#+id/rating" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="#drawable/rating_five" />
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content" android:id="#+id/range"
android:layout_height="wrap_content" android:text="Range"
android:textStyle="bold" android:singleLine="true" android:textSize="16sp"
android:paddingRight="5dip" />
<TextView android:layout_width="fill_parent" android:id="#+id/condition"
android:layout_height="wrap_content" android:text="Condition"
android:textStyle="bold" android:singleLine="true" android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
However nothing is drawn? Where am I going wrong. Secondly is it correct to set the width and heoght of the shape in the View or should I be doing it in the damage.xml? For example
<shape xmlns:android="http://schemas.android.com/apk/res/android"
shape="rectangle">
<solid color="#ff0000" />
<size android:height="wrap_content" />
<size android:width="5dip" />
<stroke width="3dp" color="#ff0000" />
Here the compiler complains about wrap_content.
Any help would be greatly appreciated.
Try changing color="#ff0000" to android:color="#ff0000". That should cause the rectangle to be visible. Once you do that, you will find that a red rectangle shows up, but it fills the parent view vertically. That is because you used android:layout_height="wrap_content", even though the rectangle does not have any fixed height. I would fix that by using some other value for android:layout_height in your layout.
Also, it appears that you have placed damage.xml in the layout directory. Since a shape is a drawable, you should place it in the drawable directory, and reference it as #layout/damage in your layout.
Update:
Using the following code in damage.xml causes the rectangle to show up fine for me.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#f0f000" />
<stroke android:width="3dp" android:color="#ff0000" />
</shape>

Categories

Resources