How to change the start posititon in a edittextfield - android

My login screen locks like this
http://pbrd.co/UVekFg
with that code
<TextView
android:id="#+id/login_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:text="#string/login_label_text" />
<EditText
android:id="#+id/username"
android:layout_width="#dimen/textfield_width"
android:layout_height="#dimen/textfield_height"
android:background="#drawable/textfeld"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/login_password_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/password" />
<EditText
android:id="#+id/login_password"
android:layout_width="#dimen/textfield_width"
android:layout_height="#dimen/textfield_height"
android:background="#drawable/textfeld"
android:inputType="textPassword" />
Actually the first character starts directly on the left border of the edittextfield. Is there an option so that there a bit padding between the first character and the left border of my textbox?
Thanks

You should probably provide padding for all the four edges of the widget by declaring android:padding = 5dp attribute in your EditText.
From what I see in your screen shot, it would be better to use android:layout_margin attribute to provide breathing space between your widgets.

You'll want to set android:padding
But if you plan on using this custom EditText throughout your app, you may want to create a style and store all the custom pieces in there.
So for example in your styles.xml, you'd have:
<style name="Custom.EditText.Style" parent="#android:style/Widget.EditText">
<item name="android:background">#drawable/textfeld</item>
<item name="android:paddingLeft">6dp</item>
<item name="android:paddingTop">4dp</item>
<item name="android:paddingBottom">4dp</item>
</style>
Then in your xml layout, all you'd need is:
<EditText
...
style="#style/Custom.EditText.Style"
/>

Related

TextView is not setting textstyle, color and anything

I am setting style,color and size to textview , that is working
this is my code `
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txt_agent_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center"
android:textColor="#000"
android:textSize="14sp"
android:textStyle="italic"/>
Please check your parent layout is correct some times transparent layer or such things create visualise problem with colour
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txt_agent_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:gravity="center"
android:text="AppCompatTextView"
android:textColor="#FFFFFF"
android:textSize="114dp"
android:textStyle="italic" />
Use Dimension for setting up a text size ,always avoid hard coding
If you want to set same style for text-color,text-size and text-style than you can create something like
<style name="MyTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textSize">#dimen/abc_text_size_body_1_material</item>
<item name="textColor">?textColorPrimary</item>
<item name="textStyle">italic</item>
</style>

Autocomplete suggestion hiding the AutocompleteTextview Field partially

I want to know why my autocomplete textview suggestion is hiding the autocomplete textview , i am attaching the picture for better understanding.
<AutoCompleteTextView
android:id="#+id/current_location"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/round_background_white"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingLeft="5dp"
android:completionThreshold="1"
android:dropDownHeight="80dp"
android:dropDownWidth="wrap_content"
android:singleLine="true"
android:focusable="true"
android:textColor="#000000"
android:textColorHint="#000000"
android:dropDownListViewStyle="#style/DropDownListViewStyle"/>
Style.xml:
<style name="DropDownListViewStyle">
<item name="android:dividerHeight">2dp</item>
</style>
It's probably due to the custom drawable round_background_white.
Make sure you are specifying enough height & padding in it.
Also post your round_background_white over here.

letter in textview on android is too low

I've developed a game, which has boxes of textview with 1 letter within it.
in the emulator everything works fine, but, when i try to see it on my phone, the letter shifts down, and cuts the letter in the middle.
currently, my style is as so :
<style name="MoveLetter">
<item name="android:layout_width">#dimen/BoxSize</item>
<item name="android:layout_height">#dimen/BoxSize</item>
<item name="android:background">#drawable/blue_box_md_lighter</item>
<item name="android:contentDescription">#string/temp</item>
<item name="android:gravity">center</item>
<item name="android:scaleType">fitCenter</item>
<item name="android:textStyle">bold</item>
<item name="android:typeface">serif</item>
<item name="android:visibility">visible</item>
</style>
I use this style in my xml(partly) :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/game7_336letters"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/woodbackground1lighter_a_rotated"
android:orientation="vertical" >
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter1"
android:layout_marginLeft="180dp" android:layout_marginTop="30dp" android:textIsSelectable="true" />
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter2"
android:layout_marginLeft="240dp" android:layout_marginTop="30dp" android:textIsSelectable="true" />
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter3"
android:layout_marginLeft="300dp" android:layout_marginTop="30dp" android:textIsSelectable="true" />
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter4"
android:layout_marginLeft="180dp" android:layout_marginTop="175dp" android:textIsSelectable="true" />
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter5"
android:layout_marginLeft="240dp" android:layout_marginTop="175dp" android:textIsSelectable="true" />
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter6"
android:layout_marginLeft="300dp" android:layout_marginTop="175dp" android:textIsSelectable="true" />
I've tried many options to add to the style - PaddingBottom,PaddingTop, layout_gravity = center, gravity = layout_horizontal, gravity = layout_vertical : all didn't help.
as far as right / left alignment - its good, the letter is in the center of the textview.
i'd appreciate any help you may have to offer..
Try specifying textSize, and make it smaller than your BoxSize dimen. Different letters have different dimensions, so it will be tricky to get right across different density devices.
incase anyone else has this issue : i figure out a way to pass the problem :
if you set the padding on code behaind, problem solved (for me at least..)
TextView tv = findViewById(...);
tv.setPadding( 0, -25,0,0);

TextView Ellipsize (...) not working

I want to have a single lined TextView to show up 3 dots at the end when the text is longer than the TextView. I don't know why - but I don't get it.
I already wrapped my head around similar StackOverflow questions, but I ended up with no solution. Maybe someone has some useful hints.
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<TextView
android:textStyle="bold"
android:text="Full Name"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_width="wrap_content"
android:id="#+id/lName"
android:layout_gravity="center_vertical"
android:maxLines="1"
android:ellipsize="end"/>
</LinearLayout>
The LinearLayout above is nested into 2 other LinearLayouts. Maybe this is important to know. I already tried the attribute "singleLine" too, but some say this is deprecated and it doesnt work anyway.
Add the following styles in your styles file (typically styles.xml):
<style name="autoscroll">
<item name="android:singleLine">true</item>
<item name="android:ellipsize">marquee</item>
<item name="android:marqueeRepeatLimit">marquee_forever</item>
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:scrollHorizontally">true</item>
</style>
Then add the style #style/autoscroll to your TextView:
<TextView android:id="#+id/lName"
style="#style/autoscroll" />
You can reuse your autoscroll feature easily when you want this way.
Add this in your xml for the TextView:
android:maxWidth="200dp"
android:maxLines="1"
As
android:singleLine="true"
is deprecated.
android:id="#+id/lName" android:layout_width="150dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:text="Avinljhakjhsajkhakjshda"
android:textSize="16sp"
This doesn't work with me unless adding 'android:ems' attribute along with the android:ellipsize attribute
android:ellipsize="end"
android:singleLine="true"
android:ems="8"
The ellipses did not appear while my text was selectable.
I needed to disable selectable text (which is the default):
android:layout_width="0dp" (match constraint)
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textIsSelectable="false"
It works with singleLine="true" but this attribute is now deprecated, use ellipsize and scrollHorizontally="true" instead.
Use this code it will definitely work.
<TextView
android:id="#+id/sAddress"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="Adress"
android:textSize="14sp"/>

Android: how to make two TextViews placed in different lines if there is not enough space in one line

I'm trying to organize two TextViews to behave like that:
So, if there is enough space for both TextViews in line, android should place them in line.
If there is not enough space, the second TextView must be placed on the next line with right alignment.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/takeoffCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/flightItem" />
<TextView
android:id="#+id/landingCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/flightItem" />
</LinearLayout>
<style name="flightItem" parent="#android:style/TextAppearance">
<item name="android:textSize">14dip</item>
<item name="android:textColor">#color/flightItemFont</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textStyle">bold</item>
</style>
To accomplish what you are looking for you could change you're layout to a RelativeLayout and add android:layout_alignParentLeft="true" to your TextViews, however, this doesn't set these TextViews to act dynamically. Meaning if they can fit side-by-side then they should be in-line but the bottom TextView will still align to the right.
I don't think what you are looking for is technically possible. However this may be a good alternative:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/takeoffCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
style="#style/flightItem" />
<TextView
android:id="#+id/landingCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
style="#style/flightItem" />
</RelativeLayout>

Categories

Resources