How to set focus on a TextView when an Activity starts?

前端 未结 7 1488
我在风中等你
我在风中等你 2020-12-28 15:49

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         


        
相关标签:
7条回答
  • 2020-12-28 16:25

    In order to request focus to TextView you need to set focusable="true" and focusableInTouchMode="true" as follows:

     <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Heading"
                android:textSize="20sp"
                android:textStyle="bold"
                android:focusable="true"
                android:focusableInTouchMode="true">
                    <requestFocus />
         </TextView>
    
    0 讨论(0)
提交回复
热议问题