【问题标题】:How to remove dash in long string textview android?如何在长字符串textview android中删除破折号?
【发布时间】:2017-11-12 05:29:40
【问题描述】:

我有一个 textview 来显示进程的结果,但是当结果太长(超过我的 textview 宽度)时,它会自动附加一个破折号,如蓝色圆圈(在图片中)。如何在不使其可滚动的情况下将其删除,只需删除破折号?

【问题讨论】:

  • 您可以使用替换功能将破折号替换为空格,例如 String str="your result"; str=str.replace("-","");
  • 或使用textView.setText(editText.getText().toString().replace("-",""));
  • 不,不是我认为的代码。我的代码实际上就像 textView.setText("HereIsMyLongStringWithoutSpace")。所以问题出在布局或 XML 上(也许)。
  • 分享xml和java代码。
  • Hyphenation in Android的可能重复

标签: android xml android-layout textview


【解决方案1】:

如果您使用 api 23 或更高版本,您可以使用 android:breakStrategy 和值 BREAK_STRATEGY_SIMPLE

【讨论】:

    【解决方案2】:

    这可能不是您问题的正确解决方案,但它会帮助您实现这一目标。 使用 EditTextView 代替 TextView 并设置 android:focusableInTouchMode="false",android:focusable="false" ,然后 EditTextView 将像 TextView 一样工作,它不会显示破折号(-)符号

    【讨论】:

      【解决方案3】:

      在你的 TextView android:hyphenationFrequency="none" 上添加这个,这将删除连字符

      【讨论】:

        【解决方案4】:

        现在可以使用软连字符 -> 在字符串中使用 \u00AD,例如:

        <string name="einzelfahrt_name">Einzelfahrrad\u00ADkarte</string>

        另外,在您的 TextView 中,您必须添加:

         android:hyphenationFrequency="full"
        

        【讨论】:

          猜你喜欢
          • 2017-08-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-03-09
          • 2015-09-11
          • 2022-01-15
          • 1970-01-01
          相关资源
          最近更新 更多