2014-01-28 227 views
9
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 
<solid android:color="#ffffff" />  
<stroke android:width="1dp" 
    android:color="#000000" /> 
</shape> 

我在setBackgroundResource(R.drawable.selfbg);使用此代码 虽然我使用此代码,但在Edittext中不显示光标。Android编辑文本光标不可见?

回答

25

你试过了吗?

android:textCursorDrawable属性设置为@null应导致使用android:textColor作为光标颜色。

3

尝试:

<item name="android:textCursorDrawable">@null</item> 

它需要API-12及以上,但。

5

尝试下面添加到的EditText:

android:textCursorDrawable="@null" 
android:background="@null" 
+0

请告诉我在Java代码.... –

0

我认为你不能 “setTextCursorDrawable” 的代码。

我查看了Android的文档EditTextTextView并且没有这样的方法。

所以你必须在xml布局中做到这一点。

1
<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textCursorDrawable="@drawable/color_cursor" 
    android:background="@drawable/R.drawable.selfbg"/> 


Than create drawalble xml: color_cursor 

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <size android:width="2dp" /> 
    <solid android:color="#000000" /> 
</shape> 
0

试试这个

在你的EditText,使用属性:

android:textCursorDrawable="@drawable/black_cursor" 

和绘制black_cursor.xml添加到您的资源,如下所示:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
    <size android:width="0dp" /> 
</shape> 
0

如果你只需要通过java代码完成 试试这个

在TextView的类,你可以在下面找到

case com.android.internal.R.styleable.TextView_textCursorDrawable: 
    mCursorDrawableRes = a.getResourceId(attr, 0); 
    break; 

的代码,但该方法textCursorDrawable()仅在R.attr存在,如果你想设置这个属性,你只能通过包括拨打以下构造方法XML文件中的editText。

public EditText(Context context, AttributeSet attrs) { 
    this(context, attrs, com.android.internal.R.attr.editTextStyle); 
}