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

前端 未结 7 1486
我在风中等你
我在风中等你 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:17

    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.

提交回复
热议问题