好的,我的 main.xml 定义如下:
<LinearLayout android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<EditText android:text="EditText" android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="175px"></EditText>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_marginLeft="100px">
<Button android:id="@+id/button1" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:text="@string/btnPrint"></Button>
<Button android:id="@+id/button2" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:text="@string/btnCancel"></Button>
</LinearLayout>
</LinearLayout>
我希望能够在调用 setContentView(R.layout.main)
之前通过代码更新 EditText 的光标位置,这可能吗?如果不是,设置 EditText View 光标位置的 xml 属性是什么?
谢谢,
贾斯汀
最佳答案
您不能对尚未膨胀的 View 进行任何修改。所以,第一个答案是否。
至于第二次尝试这个标签<requestFocus />
在您的编辑文本中:
<EditText ...>
<requestFocus />
<EditText/>
关于Android:您可以在代码中编辑在 xml 中创建的 View 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5340450/