编辑文本及其光标位置?

时间:2011-09-23 12:16:24

标签: android

在Android的“编辑文本”视图中,我们可以在编辑文本视图的中间编写文本,就像在MS Word中一样。意味着写对齐,离开我们的视图中间?

5 个答案:

答案 0 :(得分:2)

在xml文件中使用:android:gravity =“top | bottom | left | right | center”

答案 1 :(得分:0)

是。将edittext的重力设置为居中。

答案 2 :(得分:0)

使用public int getSelectionStart ()和public int getSelectionEnd (),更多内容使用

http://developer.android.com/reference/android/widget/TextView.html#getSelectionStart()

答案 3 :(得分:0)

是的,试试这段代码:

editText.setGravity(Gravity.CENTER_HORIZONTAL);

答案 4 :(得分:0)

问题正文中缺少光标位置部分 - 这有什么相关性?

如果要将文本设置为静态居中,可以使用android:gravity="center_horizontal"

<EditText android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1234" android:layout_weight="1" android:id="@+id/editText1" android:gravity="center_horizontal"></EditText>

看起来像: enter image description here

你的问题中不太清楚的是,如果你想在一个文本字段中混合使用对齐,那么我假设一个对齐定义就足够了