【问题标题】:Show number of lines in text editor在文本编辑器中显示行数
【发布时间】:2017-05-14 08:03:21
【问题描述】:

我想制作我想在屏幕左侧显示number of lines的文本编辑器

像这张图片一样,编辑文本中写入的行数显示为 1、2、3 等

当用户向上或向下滚动时,我还希望行数也滚动。提前谢谢

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.osama.cryptofmroot.extras.TextEditorActivity">


    <android.support.v7.widget.AppCompatEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/type_here"
        android:inputType="textMultiLine"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="16dp"
        android:paddingBottom="16dp"
        android:id="@+id/editor_area"
        android:backgroundTint="@android:color/transparent"
        />

    </ScrollView>

【问题讨论】:

  • 如果您决定使用的小部件无法做到这一点,您可以创建自己的(创建一个扩展 APpCOmpatEditText 的新类)或查找库。
  • 我只想知道屏幕左侧的行数可以吗??
  • 如果你不能用 AppCompatEditText 来做,你必须创建你自己的类来扩展 AppCompatEditText 或者找一个库来做。我不知道你是否可以在其中显示线条,所以这是你必须弄清楚的事情。查找文档,看看是否有任何方法可以显示行号。如果没有创建您自己的版本或查找库
  • 就像@LunarWatcher 所说,您需要自己创建一个CustomView,或者为此使用一个库(如果存在)。

标签: android xml android-edittext


【解决方案1】:

我看到您使用的是 EditText 视图,因此您可以在此处找到如何创建自定义 EditText 的教程,其中包含行号:

https://mahbubzaman.wordpress.com/2015/05/11/custom-edittext-with-line-number/

希望对你有帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-18
    • 1970-01-01
    • 2011-01-04
    相关资源
    最近更新 更多