Edittext中显示的多个光标 [英] multiple cursor shown in Edittext

查看:80
本文介绍了Edittext中显示的多个光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临一个奇怪的问题.在我的EditText中:

1)当用户键入任何内容时,我可以看到多个光标.

2)提示即使在用户键入内容时也可见. 请参阅屏幕截图

以下是布局XML:

   <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
         >

        <AutoCompleteTextView
            android:id="@+id/actvCountry"
            style="@style/autoCompleteTextTheme"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="15dp"
            android:background="@drawable/edittext_background"
            android:hint="@string/select_country_hint"
            android:singleLine="true"
            android:textColor="@color/white"
            android:textColorHint="@color/hint_color"
            android:textSize="26sp" />

        <EditText
            android:id="@+id/etMobileNumber"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/tvCode"
            android:layout_alignBottom="@+id/tvCode"
            android:layout_alignLeft="@+id/tvCode"
            android:layout_marginRight="15dp"
            android:background="@drawable/edittext_background"
            android:ems="10"
            android:hint="@string/mobile_number"
            android:inputType="number"
            android:maxLength="12"
            android:paddingLeft="80dp"
            android:singleLine="true"
            android:textColor="@color/white"
            android:textColorHint="@color/hint_color"
            android:textSize="26sp" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@id/tvCode"
            style="@style/editTextTheme"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/actvCountry"
            android:layout_margin="15dp"
            android:singleLine="true"
            android:text=""
            android:textColor="@color/white"
            android:textColorHint="@color/white"
            android:textSize="26sp" />

        <TextView
            android:id="@+id/tvMsg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/etMobileNumber"
            android:layout_below="@id/etMobileNumber"
            android:layout_marginBottom="15dp"
            android:layout_marginRight="2dp"
            android:layout_marginTop="10dp"
            android:ellipsize="marquee"
            android:text="@string/enter_country_code_mobile"
            android:textColor="@color/white"
            android:textColorHint="@color/white" />

        <Button
            android:id="@+id/btnProceed"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvMsg"
            android:layout_margin="15dp"
            android:background="@drawable/ripple_button_selector"
            android:padding="7dp"
            android:text="@string/login"
            android:textAllCaps="false"
            android:textColor="@color/white"
            android:textSize="26sp" />
    </RelativeLayout>

以下是EditText(edittext_background.xml)中设置的背景

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
    android:width="2dip"
    android:color="@color/white" />
<padding
    android:bottom="5dip"
    android:left="5dip"
    android:right="10dip"
    android:top="5dip" />

欢迎任何建议.

解决方案

我不知道为什么会出现问题,但是在修改了我的edittext_background之后,问题得到了解决.我添加了透明背景.新的XML是:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
    android:width="2dip"
    android:color="@color/white" />
 <solid android:color="#00000000" />
<padding
    android:bottom="5dip"
    android:left="5dip"
    android:right="10dip"
    android:top="5dip" />

i am facing a weird problem. In my EditText:

1) I can see multiple cursor when user type anything.

2) Hint is also visible even when user is typing something. Kindly refer to the screenshot

Following is layout XML:

   <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
         >

        <AutoCompleteTextView
            android:id="@+id/actvCountry"
            style="@style/autoCompleteTextTheme"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="15dp"
            android:background="@drawable/edittext_background"
            android:hint="@string/select_country_hint"
            android:singleLine="true"
            android:textColor="@color/white"
            android:textColorHint="@color/hint_color"
            android:textSize="26sp" />

        <EditText
            android:id="@+id/etMobileNumber"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/tvCode"
            android:layout_alignBottom="@+id/tvCode"
            android:layout_alignLeft="@+id/tvCode"
            android:layout_marginRight="15dp"
            android:background="@drawable/edittext_background"
            android:ems="10"
            android:hint="@string/mobile_number"
            android:inputType="number"
            android:maxLength="12"
            android:paddingLeft="80dp"
            android:singleLine="true"
            android:textColor="@color/white"
            android:textColorHint="@color/hint_color"
            android:textSize="26sp" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@id/tvCode"
            style="@style/editTextTheme"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/actvCountry"
            android:layout_margin="15dp"
            android:singleLine="true"
            android:text=""
            android:textColor="@color/white"
            android:textColorHint="@color/white"
            android:textSize="26sp" />

        <TextView
            android:id="@+id/tvMsg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/etMobileNumber"
            android:layout_below="@id/etMobileNumber"
            android:layout_marginBottom="15dp"
            android:layout_marginRight="2dp"
            android:layout_marginTop="10dp"
            android:ellipsize="marquee"
            android:text="@string/enter_country_code_mobile"
            android:textColor="@color/white"
            android:textColorHint="@color/white" />

        <Button
            android:id="@+id/btnProceed"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvMsg"
            android:layout_margin="15dp"
            android:background="@drawable/ripple_button_selector"
            android:padding="7dp"
            android:text="@string/login"
            android:textAllCaps="false"
            android:textColor="@color/white"
            android:textSize="26sp" />
    </RelativeLayout>

Following is the background set in EditText (edittext_background.xml)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
    android:width="2dip"
    android:color="@color/white" />
<padding
    android:bottom="5dip"
    android:left="5dip"
    android:right="10dip"
    android:top="5dip" />

Any suggestion are welcome.

解决方案

I don't know why problem was coming, but it got resolved after modifying my edittext_background. I have added transparent background. New XML is:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
    android:width="2dip"
    android:color="@color/white" />
 <solid android:color="#00000000" />
<padding
    android:bottom="5dip"
    android:left="5dip"
    android:right="10dip"
    android:top="5dip" />

这篇关于Edittext中显示的多个光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆