【问题标题】:Custom Edit Text Pointer Position自定义编辑文本指针位置
【发布时间】:2015-03-11 20:09:55
【问题描述】:

好的,所以我对 Android 有点陌生。所以我非常关注一些在线教程来让自己参与一些开发。

我是计算机科学专业的本科生,因此我对 Java 的了解非常广泛。我只是在使用 XML 时遇到了一些问题,因为我以前没有使用过它。

我正在尝试使用一些简单的登录表单创建一个 LoginActivity。

我需要将指针稍微向右移动,这样它就在盒子里面。

这是我的 .xml 文件。

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.unibites.LoginActivity" >

<ImageButton
    android:id="@+id/signinBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="159dp"
    android:background="#00000000"
    android:contentDescription="@string/desc"
    android:src="@drawable/signin_btn" />

<EditText
    android:id="@+id/userEt"
    android:inputType="text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/signinBtn"
    android:layout_alignRight="@+id/signinBtn"
    android:layout_marginBottom="86dp"
    android:background="@drawable/text_field"
    android:ems="10" />

Link to the Simulator Image, where the pointer is currently at.

【问题讨论】:

  • 您是否尝试过userEt.setSelection(position);,其中位置是您要设置光标位置的索引/偏移量

标签: java android xml eclipse android-edittext


【解决方案1】:

我不知道你在这里添加了什么

android:background="@drawable/text_field"

没有这个 xml 属性/属性,活动运行得非常好! :)

更多的代码或细节会更有帮助...

编辑无法截取光标的屏幕截图(该死的闪烁!:P)

相关答案

首先,指针在它应该在的地方闪烁……它是需要整理的图像

您的问题将通过在编辑文本中使用 9patch 图像来解决。

使用link 将您的图像转换为 9patch,然后在您的视图中使用它

如需更多信息,请联系Android Developers Link

附:我用它现在它工作了。

【讨论】:

  • 我们将不胜感激。
  • 编辑文本框的背景图片。我需要图像在那里,并且由于图像,编辑文本将其对齐到图像的最左侧位置。
猜你喜欢
  • 2011-03-11
  • 2014-04-25
  • 1970-01-01
  • 1970-01-01
  • 2012-01-27
  • 2020-06-22
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
相关资源
最近更新 更多