0

我有一个用于描述的EditText。在输入过程中使字符数可见

在它下面,我有一个TextView,显示在EditText中输入的字符数。

例子:

enter image description here

的用户应该能够在输入时看到现场字符数,但在这一刻characted计数器由键盘隐藏:

enter image description here

我能做些什么来纠正?

这里是我的XML代码:

<EditText 
     android:id="@+id/MyDescription" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@null" 
     android:maxLength="500" 
     android:hint="Description" /> 

    <TextView 
     android:id="@+id/MyDescriptionCharCount" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="0/500" 
     android:layout_below="@id/MyDescription" 
     android:layout_marginTop="5dp" 
     android:layout_marginRight="3dp" 
     android:layout_marginEnd="3dp" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" /> 

父是一个RelativeLayout的。

+0

刚刚发现这个修复后,它可以帮助你的http://计算器。 com/questions/27858987 /定位编辑文本键盘以上 –

+0

谢谢,但它似乎并没有帮助我 –

+0

你终于找到一个解决方案? –

回答

1

您必须使用TextWatcher扩展该类并覆盖beforeTextChanged(),beforeTextChanged(),onTextChanged()。

EditText MyDescription = (EditText)findViewById(R.id. MyDescription); 
MyDescription.addTextChangedListener(new TextWatcher() { 
@Override 
public void afterTextChanged(Editable s) { 
    // TODO Auto-generated method stub 
} 

@Override 
public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
    // TODO Auto-generated method stub 
} 

@Override 
public void onTextChanged(CharSequence s, int start, int before, int count) { 
    // s.toString().trim().length(); 
} 

});

您可以尝试以下布局。

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

    <EditText 
     android:id="@+id/edit_text" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginLeft="16dp" 
     android:background="@android:color/transparent" 
     android:inputType="textNoSuggestions|textMultiLine" 
     android:maxLength="200" 
     android:paddingBottom="8dp" 
     android:paddingRight="5dp" 
     android:paddingTop="8dp" 
     android:textColor="#202020" 
     android:textColorHint="#979797" 
     android:textSize="14sp"/> 


    <TextView 
     android:id="@+id/charecter_count" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/add_comment_edit_text" 
     android:layout_gravity="bottom" 
     android:layout_marginBottom="8dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginTop="8dp" 
     android:gravity="bottom" 
     android:text="0/200" 
     android:textColor="#979797" 
     android:textSize="14sp"/> 
</RelativeLayout> 
+0

程序员如何知道我要显示字符计数器?我的字符计数器下方有许多其他布局 –

+0

更改您的评论。 –

+0

对不起,但我不明白如何键盘将在我的字符柜台之后,请你解释一下吗? –

0

要查看的TextView字符计数器,清单文件的activity标签下面添加一行。

android:windowSoftInputMode="adjustResize|stateAlwaysHidden" 

这会自动将您的活动布局高达可用高度增加软输入keyboard.For详细了解此检查here.

+0

程序员如何知道我想显示字符计数器?我的字符计数器 –

+0

下方有许多其他布局,请查看我的编辑... –

相关问题