Android는 EditText에 자리 표시 자 텍스트 추가
XML에없는 클래스에 자리 표시 자 텍스트를 추가하려면 어떻게 EditText
해야합니까?
EditText
경고 대화 상자에 표시되는 코드에 다음 이 있습니다.
final EditText name = new EditText(this);
그래. 당신이 찾고있는 것은입니다 setHint(int)
. XML에서 문자열의 리소스 ID를 전달하기 만하면됩니다.
편집하다
그리고 XML에서는 간단합니다. android:hint="someText"
android:hint="text"
사용자가 구체적으로 작성해야하는 정보를 제공합니다. editText
예를 들면 :-숫자 값과 문자열 값에 대한 두 개의 편집 텍스트가 있습니다. 사용자에게 힌트를 줄 수있어 어떤 가치를 주어야하는지 이해할 수 있습니다.
android:hint="Please enter phone number"
android:hint="Enter name"
응용 프로그램을 실행 한 후이 두 개의 편집 텍스트는 입력 된 힌트를 표시하고 편집 텍스트를 클릭 한 후 사용자가 원하는 것을 입력 할 수 있습니다 (고급 모드 이미지 참조)
당신의 활동에서
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="@null"
android:hint="Text Example"
android:padding="5dp"
android:singleLine="true"
android:id="@+id/name"
android:textColor="@color/magenta"/>
이것은 * !!로 변환되지 않은 힌트를 가진 입력 암호를 만드는 방법입니다.
XML에서 :
android:inputType="textPassword"
android:gravity="center"
android:ellipsize="start"
android:hint="Input Password !."
감사 : mango와 rjrjr에 대한 통찰력 : D.
Android Studio에서는 GUI를 통해 힌트 (장소 홀더)를 추가 할 수 있습니다. 먼저 디자이너보기에서 EditText 필드를 선택하십시오. 그런 다음 IDE의 Component Tree 왼쪽을 클릭하십시오 (일반적으로 존재하지만 최소화 될 수 있습니다) . 선택된 EditText의 속성 을 볼 수 있습니다 . 아래 그림과 같은 힌트 필드 찾기
거기에서 EditText에 힌트 (장소 홀더)를 추가 할 수 있습니다
레이아웃에서 추가 할 위치를 의미하는 경우 FrameLayout과 같은 컨테이너를 정의하고이 EditText를 만들 때 컨테이너에 추가 할 수 있습니다.
<LinearLayout xmlns=".."/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
FrameLayout layout = (FrameLayout) findViewById(R.id.container);
layout.addView(name);
필드를 선택한 후에도 힌트 텍스트의 동작과 달리 텍스트를 EditText보기에 삽입하려면 다음과 같이하십시오.
자바에서
// Cast Your EditText as a TextView
((TextView) findViewById(R.id.email)).setText("your Text")
코 틀린에서
// Cast your EditText into a TextView
// Like this
(findViewById(R.id.email) as TextView).text = "Your Text"
// Or simply like this
findViewById<TextView>(R.id.email).text = "Your Text"
참고 URL : https://stackoverflow.com/questions/8221072/android-add-placeholder-text-to-edittext
'Programming' 카테고리의 다른 글
"else if"가 "switch () case"보다 빠릅니까? (0) | 2020.03.02 |
---|---|
Windows에서 PYTHONPATH에 추가하여 모듈 / 패키지를 찾는 방법은 무엇입니까? (0) | 2020.03.02 |
쿼리 문자열 매개 변수를 추가하거나 업데이트하려면 어떻게합니까? (0) | 2020.03.02 |
Mongo에서“null이 아님”을 어떻게 쿼리합니까? (0) | 2020.03.02 |
내 앱의 갤러리 (SD 카드)에서 이미지를 선택하는 방법은 무엇입니까? (0) | 2020.03.02 |