1 回答
TA贡献1862条经验 获得超7个赞
参考这个例子:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:hint="Enter name"
android:inputType="textCapSentences|textNoSuggestions|textMultiLine" />
<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:hint="Description"
android:inputType="textCapSentences|textNoSuggestions|textMultiLine"
android:maxLines="6"
android:minLines="3" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="Clickhandle"
android:text="Click" />
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText=findViewById(R.id.etEmail);
// editText.setSelectAllOnFocus(true); --> Select all text inside EditText when it gets focus
}
public void Clickhandle(View view) {
editText.requestFocus();
editText.selectAll();
editText.post(new Runnable() {
public void run() {
editText.scrollTo(0, 0);
}
});
}
}
添加回答
举报