久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

android如何在edittext中制作文本完全固定的行

android how to make text in an edittext exactly fixed lines(android如何在edittext中制作文本完全固定的行)
本文介紹了android如何在edittext中制作文本完全固定的行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想讓 use 只輸入 5 行,我試過了

I want to allow use to enter just 5 lines, I tried this

<EditText
    android:layout_below="@+id/tv_signup_descriptionError"
    android:id="@+id/et_signup_description"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dip"
    android:hint="@string/et_hint_enterDescription"
    android:singleLine="false"
    android:lines="5"
    android:gravity="top"
    android:scrollHorizontally="false"
    android:inputType="textMultiLine" 
    android:maxLines="5"/>

但我仍然可以在第五行之后按 Enter

but still I can press Enter after the fifth line

推薦答案

你不能使用任何 XML 屬性來做到這一點.

You cannot do that using any XML attributes.

maxlines代表EditText的最大高度不是輸入行數.

maxlines represents the maximum height of the EditText and not the number of input lines.

但是,您可以實現自己的代碼來檢查行數.

You can however implement your own code to check for the number of lines.

以下是不是我自己的代碼,而是取自 這個答案.

mEditText.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            // if enter is pressed start calculating
            if (keyCode == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_UP) {

                // get EditText text
                String text = ((EditText) v).getText().toString();

                // find how many rows it cointains
                editTextRowCount = text.split("\n").length;

                // user has input more than limited - lets do something
                // about that
                if (editTextRowCount >= 7) {

                    // find the last break
                    int lastBreakIndex = text.lastIndexOf("
");

                    // compose new text
                    String newText = text.substring(0, lastBreakIndex);

                    // add new text - delete old one and append new one
                    // (append because I want the cursor to be at the end)
                    ((EditText) v).setText("");
                    ((EditText) v).append(newText);

                }
            }

            return false;
        }

這篇關于android如何在edittext中制作文本完全固定的行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 成人片网址 | www.日韩在线 | 亚洲精品视频在线观看免费 | 亚洲视频1区 | 日韩视频在线一区 | 日韩和的一区二区 | 国产高清视频在线观看 | 久久精品99 | 免费观看一级特黄欧美大片 | 日日碰狠狠躁久久躁婷婷 | 一级美国黄色片 | 欧美激情一区二区三区 | 精品中文字幕在线观看 | 一区二区三区四区在线 | 亚洲欧洲激情 | 国产精品免费一区二区 | 国产精品一区在线 | 精品少妇一区二区三区日产乱码 | 日韩av美女电影 | 美女久久视频 | 亚洲精品久久久久久宅男 | 成人精品一区 | 99re6在线视频精品免费 | 青青草网 | 美女天堂在线 | 激情国产在线 | 成人在线欧美 | 日韩欧美二区 | 亚洲在线中文字幕 | 精品免费视频 | 久久视频精品 | 久久网一区二区三区 | 久久久久久国产精品免费免费男同 | 久久99国产精一区二区三区 | 国产日产欧产精品精品推荐蛮挑 | 黄a在线播放 | 午夜在线影院 | 91在线网站 | 日韩免费一二三区 | 精品久久免费 | 亚洲高清三级 |