There are an EditText and a TextView in my Activity. I want to set focus on the TextView when the Activity starts. I used the following code:
TextView my
If anyone is still wondering, you can use the following in your layout xml to make a textview focusable in touch mode:
android:focusableInTouchMode="true"
Add the TextView Property in layout
android:focusable="false"
It's work for me.
This is expected when you start the Activity using the touch screen. When in "touch mode," only a couple of Views (EditText and ListView) can receive the focus. If you start your application using the trackball you will see the focus on the TextView. What you are seeing is the correct and expected result.
Use this:
EditText mEditText = (EditText) findViewById(R.id.edit_text);
TextView myTextView = (TextView) findViewById(R.id.my_text_vew);
mEditText.setFocusable(false);
myTextView.setFocusable(true);
This takes focus off of the EditText and puts it on the TextView.
You can set focus to any widget or a TextView from the xml of the activity. Just add requestFocus before the TextView end.
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView2"
android:layout_width="470dp"
android:layout_height="wrap_content"
android:layout_marginStart="90dp"
android:layout_toEndOf="@+id/textView2"
android:ems="10"
android:textColor="#455A64"
android:textColorHint="#455A64"
android:textSize="27sp">
<requestFocus />
</AutoCompleteTextView>
I came across with your question now. Maybe after 2 years you have found a solution. But I write it here for the others that will come across with this in the future. The only thing you have to do is to go to the AndroidManifest.xml
, find the Activity
in which you want this behaviour and add this android:windowSoftInputMode="stateHidden"
. So, at the start of your Activity
no keyboard will be shown, until you touch the EditText
object.