android singleLine vs maxLines

标签 android android-layout

我认为 singleLine="true" 等同于 maxLines="1" 但我看到 Android Studio 中的以下预填充字段两者都有。有区别吗?是否存在导致两者都需要的已知错误?

<EditTextPreference
   android:key="example_text"
   android:title="@string/pref_title_display_name"
   android:defaultValue="@string/pref_default_display_name"
   android:selectAllOnFocus="true"
   android:inputType="textCapWords"
   android:capitalize="words"
   android:singleLine="true"
   android:maxLines="1" />

这是来自 pref_general.xml 文件。

最佳答案

来自安卓网站:

singleLine :

Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key. The default value is false (multi-line wrapped text mode) for non-editable text, but if you specify any value for inputType, the default is true (single-line input field mode).

Must be a boolean value, either "true" or "false".

maxLines :

Makes the TextView be at most this many lines tall. When used on an editable text, the inputType attribute's value must be combined with the textMultiLine flag for the maxLines attribute to apply.

Must be an integer value, such as "100"

请注意,自 API 3 以来,singleLine 已被弃用,而应使用 maxLines。所以你真正需要的是

android:maxLines = integer // 1 for single line or add lines multiple as well.

关于android singleLine vs maxLines,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30879471/

相关文章:

java - 使用短信自动响应来电

android - BroadcastReceiver 不会使用自定义进程名称触发

android - 带 SurfaceHolder.lockCanvas 的动态壁纸(矩形脏)

android:kotlin 如何解决数据绑定(bind)错误

android - 即使在 onCreate() 之后,布局尺寸仍然返回 0

android - 将位置转换为 LatLng

android - 将 View 添加到 RelativeLayout 会更改其大小

java - 工具栏干扰使用 SearchView 过滤 RecyclerView

android - 像 whatsapp 这样的列表项目容器

安卓。这不好用吗?是一个错误?设置边距