EditText not using its attributes in XML - android

<EditText
android:id="#+id/drawer_search"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:background="#color/white"
android:drawableLeft="#android:drawable/ic_menu_search"
android:hint="#string/drawer_search_hint"
android:imeOptions="actionSearch"
android:maxLines="1"
android:textColor="#color/dark_blue"
android:textColorHint="#color/dark_blue"
/>
So... all of the attributes work except imeOptions and maxlines. I want the text view to be only one line and the keyboard to not have a return key to go to the next line. It needs to submit/search what ever is in the text view.
So this is the text view. cropped for space.
If you press enter/return it goes to the next line(which there should only be one line).
Why isn't the textview using all of the attributes?
Is there a better way to make it so the keyboard's return button is a submit button rather than next line?
The layout file is declared like this.
View headerRoot = inflater.inflate(R.layout.drawer_header, null);

Attribute android:maxLines corresponds to the maximum height of the EditText or TextView. Use android:singleLine=true for one line input.

Related

How to expand textfield after a line of words

My textfield not expanding after line of words. I can't see my first line after write second line for text box. I want to expand automatically text field. My text field not creating new line after writing words. I can send my message but can't see another lines before send. My language is kotlin.
just use:
<TextView
android:id="#+id/textView"
android:layout_width="150dp"
android:layout_height="wrap_content"/>
Define input type in text field element .
android:inputType="textMultiLine" and layout height android:layout_height="wrap_content"
Still not solved then please attach your layout XML file.
If you want your textview to become flexible, you shouldn't give to it fixed size of
height.
Make its height "wrap_content" so textview's size will change according
to what you write inside it.
Just add:
android:layout_height="wrap_content"

Display non-editable text at end of EditText in android

I want to display text at the end of EditText as shown in the image above for URLName.How could I acheive this ?The text cannot be edited.I am using this editText inside TextInputLayout from the design library. thanks in advance
Create a LinearLayout. An example of a row inside this layout would be a title (i.e. URL name) or a text entry field.
Set the background of the LinearLayout for the current row to a custom drawable to create a thin red line. Follow the answers on this post for ideas.
For the URL entry field mentioned in your question, create a TextView and an EditText inside another LinearLayout inside the current row.
The TextView will contain ".sitename.com". Set it to wrap_content and give it a weight of 0. For your EditText, set its width to 0dp and its weight to 1. It should now fill all remaining space. Set the background to #null for both.
This worked for me :
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_alignParentLeft="true"
android:id="#+id/youeeditid"
android:layout_gravity="center"
/>
<TextView
android:id="#+id/text_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="HintText"
android:textSize="18sp"
android:layout_marginRight="10dp"
android:textColor="#808080"
/>
</RelativeLayout>
It's little bit tricky but it's works for me.
BUT
If you want to set only EditText then you can do below :
1) Set Gravity of EditText to "Right" and Ellipsize to "End" .
2) Now In onCreate() method write onclicklistener of EditText and set
Gravity as "Left".
3) Or you can also set programatically on OnKeyListener , where check
if lenght of edittext is equal to Zero set EditText's gravity as
Left.
Reference : Setting cursor to the right on an EditText with HINT Gravity to center

How to display multiple lines of text with scrolling in android?

I want to display multiple lines of text in my application in particular range such that user can scroll to view other lines. I have tried EditText, but it generates keyboard on top of it and doesn't scroll properly. Then I tried TextView, it also does not scroll the text properly as I wanted.
Is there any other option available? If No, then how to scroll the text vertically in TextView or EditText? I want to scroll the text on drag as in WebView. NOT auto scroll.
You can limit the Height of TextView to match the number of lines you user wants to see, then simply put your TextView in a ScrollView
I had done a simple example to demonstrate this...
<ScrollView android:layout_height="30dp"
android:layout_width="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:textSize="16sp"
android:id="#+id/tv1"
/>
</ScrollView>
Check below code
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="17dip"
android:inputType="textMultiLine"
android:scrollbars="vertical"
/>
It is possible to create multiline text view with scroll view. I used the following code in your application:
Txt_VistaRecetasola = (TextView) findViewById(R.id.txt_vistarectsola);
Txt_VistaRecetasola.setMovementMethod(ScrollingMovementMethod.getInstance());
Txt_VistaRecetasola.setScrollBarStyle(0x03000000);
Txt_VistaRecetasola.setVerticalScrollBarEnabled(true);
Txt_VistaRecetasola.setTextColor(0xFF000000);
Try using Edittext with making it un editable, so in this case it wont allow keyboard to popup.
android:windowSoftInputMode="stateAlwaysHidden" in your Manifest file in the activity where you have your EditText.

Android: EditText content

)
I am having a bit of a problem with my app. I am using a multiline edit text.
I want its content to have a bit of a left space (not the edittext, but the text in it), because of a drawable i set as backgroud for the edittext.
Just like padding works for layout alignment, is there anything to align text?
Try:
<EditText
.....
android:paddingLeft="50dp"
.....
/>
If you want to have a padding,
You can simply use android:paddingLeft="20dp"
or android:padding="20dp" for your EditText in your XML.(i don't know exactly what you want, just try).
If you want to align your text,
Try to use Android:Gravity in order to align your text in your EditText.
Here is the code : android:gravity="right" (in order to have right align for your text)
You can find more information about what you can do with this here : Android Gravity

In EditText ,text should come after 1 space

In edittext the text is coming leftmost corner. but i want to display the text after one space . so it should be more readable.
Any one can help me in this problem.which tag in edit text i have to use.
Try providing margins around your EditText Background like this,
<EditText android:id="#+id/tickets_value"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dip"
/>
You can use either the padding or the margin element of the view.
While margin offsets the entire view the padding offsets the content within the view.
http://developer.android.com/reference/android/view/View.html

Categories

Resources