Android에서 텍스트 편집 보기에서 다중 행을 허용하시겠습니까?
Android에서 다중 회선을 허용하는 방법EditText
보기?
기본적으로 모두EditText
Android의 위젯은 여러 줄로 표시됩니다.
다음은 몇 가지 샘플 코드입니다.
<EditText
android:inputType="textMultiLine" <!-- Multiline input -->
android:lines="8" <!-- Total Lines prior display -->
android:minLines="6" <!-- Minimum lines -->
android:gravity="top|start" <!-- Cursor Position -->
android:maxLines="10" <!-- Maximum Lines -->
android:layout_height="wrap_content" <!-- Height determined by content -->
android:layout_width="match_parent" <!-- Fill entire width -->
android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
/>
다음을 사용하는 것이 좋습니다.
<EditText
...
android:inputType="textMultiLine"
/>
그 이유는android:singleLine
사용되지 않습니다.
이것은 저에게 효과가 있습니다. 사실 이 두 가지 속성, 즉 inputType과 lines가 중요합니다.또한 스크롤바가 필요할 수도 있습니다. 아래 코드는 스크롤바를 만드는 방법을 보여줍니다.
<EditText
android:id="@+id/addr_edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|left"
android:inputType="textEmailAddress|textMultiLine"
android:lines="20"
android:minLines="5"
android:scrollHorizontally="false"
android:scrollbars="vertical" />
아래 코드 스니펫을 적용한 방법은 이렇고 잘 작동하고 있습니다.호프, 이게 누군가에게 도움이 될 거예요
<EditText
android:id="@+id/EditText02"
android:gravity="top|left"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:lines="5"
android:scrollHorizontally="false"
/>
건배!감사해요.
EditText에 singleLine 속성이 있습니다.XML에서 설정하거나 setSingleLine(false); http://developer.android.com/reference/android/widget/TextView.html#setSingleLine%28%29 을 호출하여 설정할 수 있습니다.
이것을 사용해 보세요. 이 선들을 당신의 편집 텍스트 보기에 추가하세요. 제 것을 추가하겠습니다. 이해했는지 확인하십시오.
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
<EditText
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText_newprom_description"
android:padding="10dp"
android:lines="5"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:minLines="5"
android:gravity="top|left"
android:scrollbars="vertical"
android:layout_marginBottom="20dp"/>
그리고 당신의 자바 클래스에서 다음과 같이 이 편집 텍스트에 대해 클릭 리스너를 만듭니다. 당신의 이름에 따라 내 이름, 체인 이름을 추가하겠습니다.
EditText description;
description = (EditText)findViewById(R.id.editText_newprom_description);
description.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return false;
}
});
이것은 나에게 잘 작동합니다.
android:inputType="textMultiLine"
이 코드 라인은 저에게 적합합니다.텍스트를 편집하는 이 코드를 xml 파일에 추가합니다.
이것만 추가합니다.android:inputType="textMultiLine"
관련 필드의 XML 파일에 있습니다.
AppCompatEdit를 사용하는 경우텍스트를 선택한 다음 inputType="textMultiLine"을 설정해야 합니다. 여기서 복사할 수 있는 코드가 있습니다.
<androidx.appcompat.widget.AppCompatEditText
android:padding="@dimen/_8sdp"
android:id="@+id/etNote"
android:minLines="6"
android:singleLine="false"
android:lines="8"
android:scrollbars="vertical"
android:background="@drawable/rounded_border"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_25sdp"
android:layout_marginTop="32dp"
android:layout_marginEnd="@dimen/_25sdp"
android:autofillHints=""
android:gravity="start|top"
android:inputType="textMultiLine"
/>
배경으로
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="@dimen/_5sdp"/>
<stroke android:width="1dp" android:color="#C8C8C8"/>
</shape>
이 모든 것은 좋지만 편집 텍스트가 상위 스크롤 보기 안에 있는 경우에는 작동하지 않습니다 :) 아마도 가장 일반적인 예는 보이는 영역을 넘어설 정도로 항목이 너무 많은 "설정" 보기입니다.이 경우 모든 설정을 스크롤 보기로 전환하여 설정을 스크롤할 수 있도록 합니다.설정에 여러 줄 스크롤 가능한 편집 텍스트가 필요한 경우 스크롤이 작동하지 않습니다.
이전에 테마에 할당된 줄 수를 사용하지 않으려면 xml 특성을 사용합니다.android:lines="@null"
<EditText
android:id="@id/editText" //id of editText
android:gravity="start" // Where to start Typing
android:inputType="textMultiLine" // multiline
android:imeOptions="actionDone" // Keyboard done button
android:minLines="5" // Min Line of editText
android:hint="@string/Enter Data" // Hint in editText
android:layout_width="match_parent" //width editText
android:layout_height="wrap_content" //height editText
/>
저는 이 웹사이트가 마음에 들지 않지만 http://www.pcsalt.com/android/edittext-with-single-line-line-wrapping-and-done-action-in-android/, 에서 배웠습니다.다중 행을 원하지만 Enter 버튼을 포스트 버튼으로 유지하려면 목록 보기의 "수평 스크롤"을 false로 설정합니다.
android:scrollHorizontally="false"
xml에서 작동하지 않으면 프로그래밍 방식으로 이상하게 작동합니다.
listView.setHorizontallyScrolling(false);
또 다른 깔끔한 방법은 사용하는 것입니다.android:minHeight
android:layout_height="wrap_content"
이렇게 하면 편집 내용이 비어 있을 때 편집 내용의 크기를 설정할 수 있으며, 사용자가 입력한 내용은 여러 줄을 포함하여 사용자가 입력한 양에 따라 늘어납니다.
<EditText
android:hint="Address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textMultiLine|textNoSuggestions"
android:id="@+id/edittxtAddress"
android:layout_marginLeft="@dimen/textsize2"
android:textColor="@android:color/white"
android:scrollbars="vertical"
android:minLines="2"
android:textStyle="normal" />
그리고 "\n"을 제거하는 활동에서 사용자는 다음 줄을 누릅니다.
String editStr= edittxtAddress.getText().toString().trim();
MyString= editStr.replaceAll("\n"," ");
언급URL : https://stackoverflow.com/questions/4233626/allow-multi-line-in-edittext-view-in-android
'it-source' 카테고리의 다른 글
3.2의 MongoDB 덤프, 3.4로 복원, 오류 인덱스 safe = null (0) | 2023.07.10 |
---|---|
Spring Boot to Spring Retry 주석에서 구성 속성을 주입하는 방법은 무엇입니까? (0) | 2023.07.05 |
NodeJS Types 스크립트에서 @types 버전을 관련 패키지 버전과 연결하는 방법은 무엇입니까? (0) | 2023.07.05 |
Spring Boot Swagger UI - UI 액세스 보호 (0) | 2023.07.05 |
워드프레스 웹사이트의 파이어베이스 인증 (0) | 2023.07.05 |