gpt4 book ai didi

java - ImageView 上的透明背景 EditText 不会显示光标

转载 作者:行者123 更新时间:2023-11-30 09:30:54 25 4
gpt4 key购买 nike

因此,我希望用户能够在我设置为 ImageView 的图像上进行键入。图像已设置并可以使用。当用户单击图像时,一个编辑文本框会显示在他们单击的位置。但是编辑文本的白色背景挡住了背景中的图像。因此,我将编辑文本背景设置为透明:

    editTextOne.setBackgroundColor(Color.TRANSPARENT);

这适用于使编辑文本背景透明。但是,现在光标也不会显示,除非开始输入。

所以,我想问的是,是否有办法让 EditText 背景透明,但仍然让光标显示和闪烁?任何帮助将不胜感激,谢谢!

代码:

    public boolean onTouch(View view, MotionEvent event){
if (type == true){
touchX = (int) event.getX();
touchY = (int) event.getY();
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) editTextOne.getLayoutParams();
params.leftMargin = touchX;
params.topMargin = touchY;
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
editTextOne.setLayoutParams(params);
editTextOne.setVisibility(View.VISIBLE);
editTextOne.bringToFront();
editTextOne.setBackgroundColor(Color.TRANSPARENT);
editTextOne.requestFocus();
editTextOne.setCursorVisible(true);
}//end of if statement
return true;
}//end of onTouch

XML:

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/relative" >

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toLeftOf="@+id/load"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:text="C"
android:textStyle="bold"
android:textSize="20dp"
android:id="@+id/camera"
android:onClick="camera"/>

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toLeftOf="@+id/view"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:id="@+id/load"
android:text="L"
android:textStyle="bold"
android:textSize="20dp"
android:onClick="load"/>

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:text="v"
android:id="@+id/view"
android:textStyle="bold"
android:textSize="20dp"
android:onClick="view"/>

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toLeftOf="@+id/camera"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:text="T"
android:textStyle="bold"
android:textSize="20dp"
android:id="@+id/text"
android:onClick="text"/>

<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@null"
android:visibility="invisible"
android:id="@+id/textone"/>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:inputType="textAutoCorrect"
android:singleLine="true"
android:id="@+id/edittextone"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="@+id/picture"/>

</RelativeLayout>

编辑:我不确定为什么光标不会立即显示,但我发现按下空格键后光标可见。所以,为了解决我的问题,我使用了:

     editTextOne.setText(" ");

这会放置一个空格作为初始文本,因此会显示光标。我希望这可以帮助遇到类似问题的其他人。

最佳答案

您可以在 xml 文件中更改 edittext 属性 android:background="@null",而不是在代码文件中设置,它对我有用。我希望它对您有用。

关于java - ImageView 上的透明背景 EditText 不会显示光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13079206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com