【发布时间】:2018-10-01 11:24:12
【问题描述】:
问题:字符计数器跑出屏幕
我发现很难有一个字符计数器,一旦输入文本滚动超过一个屏幕尺寸,它就不会消失。
这是我在布局 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android.support.design="http://schemas.android.com/tools">
<android.support.design.widget.TextInputLayout
android:id="@+id/textContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
android:overScrollMode="never"
android.support.design:errorEnabled="true"
android.support.design:hintEnabled="true"
app:counterMaxLength="@integer/global_comments_size">
<android.support.design.widget.TextInputEditText
android:id="@+id/action_global_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_marginTop="8dp"
android:hint="@string/edit_comments"
android:imeOptions="actionDone"
android:inputType="textMultiLine"
android:scrollbars="vertical"
android:maxLength="@integer/global_comments_size"
/>
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
counter visible until scroll leaves the screen
Counter becomes invisible as the text scroll over the screen
可能的选择:
我认为以下三个选项是可能的解决方案。
-
制作底部工具栏并以编程方式添加计数器
-
达到最大尺寸后,以编程方式制作弹出窗口
-
以某种方式在 xml 中配置 TextInputLayout 或使用其他库。
我更喜欢选项 3。但是,我现在不知所措,既没有在文档中也没有通过谷歌搜索论坛找到任何解决方案或提示。
已解决
找到解决方案
在阅读更多内容后,我发现 stackoverflow here 上已经提出了关于计数器在屏幕上运行并提供解决方案建议的问题。 但是,解决方案并不像预期的那样简单 xml 条目,而是必须以编程方式完成
【问题讨论】:
标签: android counter android-textinputlayout textedit android-textinputedittext