I have a TextView which has text selectable.
<TextView
android:textIsSelectable="true"
android:layout_marginLeft="#dimen/reading_left_margin"
android:layout_marginRight="#dimen/reading_right_margin"
android:layout_marginTop="#dimen/reading_content_title_margin"
android:textColor="#color/colorText"
android:textSize="#dimen/reading_text_size"
android:lineSpacingMultiplier="1.8"
android:id="#+id/text_content"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
In the same fragment i have an EditText.
Once I focus into the editText, I am not able to select text on the TextView any more. However, if I minimize the app and reopen, I am able to again select the text on the TextView.
<EditText
android:imeOptions="actionDone"
android:layout_margin="5dp"
android:hint="#string/type_here"
android:textColorHighlight="#00000000"
android:id="#+id/input_comment"
android:textColor="#color/colorCommentsText"
android:padding="5dp"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
I have tried textview.invalidate(), textview.requestFocus() neither seems to work.
EDIT: Forgot to mention I have done edittext.clearFocus() before trying to select text from textView.
Related
I'm making a simple test app to wrap my head around reading text from TextViews in android.
My problem is: I have 2 TextViews, one for a username and one for a password field, and a button. The button calls a method that gets text from both TextViews. However, my username TextView is automatically selected when the app runs and I can type text into it, and I cannot deselect it and select the password field to write into, but I can click the button. Does anybody know what the issue might be?
Android 7.0 used for testing
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/userField"
android:layout_width="#dimen/textView_width"
android:layout_height="#dimen/textView_height"
android:layout_above="#id/passField"
android:layout_marginHorizontal="#dimen/activity_horizontal_margin"
android:layout_marginVertical="#dimen/activity_vertical_margin"
android:background="#color/LightCoral"
android:gravity="center_vertical"
android:hint="#string/user"
android:inputType="text"
android:textAlignment="gravity"
android:textSize="10pt"
android:visibility="visible" />
<TextView
android:id="#+id/passField"
android:layout_width="#dimen/textView_width"
android:layout_height="#dimen/textView_height"
android:layout_centerInParent="true"
android:layout_marginHorizontal="#dimen/activity_horizontal_margin"
android:layout_marginVertical="#dimen/activity_vertical_margin"
android:background="#color/LightCoral"
android:gravity="center_vertical"
android:hint="#string/pass"
android:inputType="textPassword"
android:textAlignment="gravity"
android:textSize="10pt"
android:visibility="visible" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/passField"
android:layout_centerHorizontal="true"
android:width="#dimen/button_width"
android:height="#dimen/button_height"
android:background="#color/FireBrick"
android:onClick="uradi"
android:text="#string/button_tag"
android:textColor="#color/Black" />
</RelativeLayout>
EditText is better widget over TextView for handling user input. Replace your TextView with EditText
You should choose the controls that are suitable for the use of the sense.
The input of the username and password is generally used for EditText
Hi, I have a UI like the picture above, when the "forgot?" text clicked it will open another activity, this is an EditText view, Is there any way I can do to add the "forgot?" text and make it clickable?
This should fit your needs:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="#+id/et_password"
android:hint="Password"/>
<TextView
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/et_password"
android:text="Forgot?" />
</RelativeLayout>
Just set an OnClickListener to the TextView and you are good to go :)
I don't know why is this happening.. In other activities EditText is working fine. This is how my fragment layout looks:
<EditText
android:gravity="center"
android:inputType="text"
android:background="#android:color/transparent"
android:layout_below="#+id/profile_image"
android:text="Dusan Dimitrijevic"
android:layout_centerHorizontal="true"
android:textSize="18sp"
android:layout_marginTop="20dp"
android:textColor="#android:color/black"
android:id="#+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Is something affecting in layout these EditTexts so they can't be editable. If i need to show you Java code, let me know. I can set text to EditText by the way, but can't edit it..
Remove the background and the text. Use hint instead of text
<EditText
android:gravity="center"
android:inputType="text"
android:hint="Dusan Dimitrijevic"
android:layout_below="#+id/profile_image"
android:layout_centerHorizontal="true"
android:textSize="18sp"
android:layout_marginTop="20dp"
android:textColor="#android:color/black"
android:id="#+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
I encountered this and resolved by identifying an overlapping layout/element declared below editText thus preventing interaction with the editText element. My editText element envelop (parent) layout had the same:
android:layout_below="#+id/xxxxxx"
specification as the layout below it.
i used edit text for scroll option, and it display text i wrote.
the problem is that when the activity whith this edit text open
it show the text from the end, and i need to scroll up to see the beginig
thans
this is the code (xml):
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView4"
android:layout_alignRight="#+id/imageView4"
android:layout_below="#+id/imageView4"
android:layout_marginTop="17dp"
android:background="#null"
android:cursorVisible="false"
android:editable="false"
android:ems="10"
android:gravity="top"
android:singleLine="false"
android:lines="8"
android:inputType="none"
android:
android:scrollbars="vertical"
android:text="Some Long String"
android:textColor="#android:color/white" >
You can set the cursor position in your Activity's onCreate() with setSelection():
EditText editText1 = (EditText) findViewById(R.id.editText1);
editText1.setSelection(0);
i used edit text for scroll option
If you only want to let the user scroll through your text, it is easier to use a ScrollView:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
... />
</ScrollView>
I have an activity where the user is presented with a list of edit texts. The problem is, as soon as the activity starts, the virtual keyboard is brought up right away for the first edit text. I don't want this to happen as there is a spinner before this edit text, and often I've found that popping up the keyboard like this makes the user forget about that previous spinner.
Here's the relevant code:
<Spinner
android:id="#+id/event_location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30px"
android:prompt="#string/location_prompt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Event Name: " />
<EditText
android:id="#+id/event_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity Type: " />
<Spinner
android:id="#+id/event_type"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address: " />
<EditText
android:id="#+id/event_address"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Summary: activity with an EditText starts, and the virtual keyboard automatically pops up. I don't want it to do this unless the user presses on the edit text.
Thanks for any help.
The EditText is automatically set to focus so you need to put android:focusable="false" or editText.setFocusable(false) to prevent the EditText to be focused while the spinner is visible. You could also try editText.setSelected(false).
Try changing your spinner XML to this:
<Spinner
android:layout_marginTop="30px"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/event_location"
android:prompt="#string/location_prompt">
<requestFocus />
</Spinner>
Also try to do for each EditText:
android:focusable="false"
android:focusableInTouchMode="false"
Look at this post: Stop EditText from gaining focus at Activity startup
This is how it works for me:
to make sure the edit text wont get focus on startup:
In xml set the focusable attribute of the EditText to false:
android:focusable="false"
2. in order to make the EditText focusable again after startup:
set the focusable attribute from code in the oncreate() method of the wanted activity after the setContent() method:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main_view);
....
EditText et = (EditText) findViewById(R.id.et_notes);
et.setFocusable(true);
et.setFocusableInTouchMode(true);
...
}