의 선택 내가 글고 만든 다음 코드로 서식을 포함 텍스트를 추가했습니다되지 않습니다 :SpannableString (빌더) 글고
EditText richTextView = (EditText)findViewById(R.id.rich_text);
// this is the text we'll be operating on
SpannableStringBuilder text = new SpannableStringBuilder("Lorem ipsum dolor sit amet");
// make "Lorem" (characters 0 to 5) red
text.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);
// make "ipsum" (characters 6 to 11) one and a half time bigger than the textbox
text.setSpan(new RelativeSizeSpan(1.5f), 6, 11, 0);
// make "dolor" (characters 12 to 17) display a toast message when touched
final Context context = this;
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View view) {
Toast.makeText(context, "dolor", Toast.LENGTH_LONG).show();
}
};
text.setSpan(clickableSpan, 12, 17, 0);
// make "sit" (characters 18 to 21) struck through
text.setSpan(new StrikethroughSpan(), 18, 21, 0);
// make "amet" (characters 22 to 26) twice as big, green and a link to this site.
// it's important to set the color after the URLSpan or the standard
// link color will override it.
text.setSpan(new RelativeSizeSpan(2f), 22, 26, 0);
text.setSpan(new ForegroundColorSpan(Color.GREEN), 22, 26, 0);
// make our ClickableSpans and URLSpans work
richTextView.setMovementMethod(LinkMovementMethod.getInstance());
// shove our styled text into the TextView
richTextView.setText(text, BufferType.EDITABLE);
내 문제는 실행할 때 텍스트가 선택되지 않는 것입니다 프로그램 (에뮬레이터와 내 장치 모두에서 시도). "dolor"를 제외한 단어를 클릭하면 커서가 나타나지 않지만 입력하면 "Lorem"이전에 타이핑이 시작됩니다. 그러나 "dolor"를 클릭하면 단어가 선택되고 바꿀 수 있습니다 (단, 바꾸지 않고 입력 할 수는 없습니다).
단어의 다른 부분을 선택할 수없고 원하는 위치에 커서를 놓을 수 없습니다 (심지어 표시되지 않습니다).
SpannableString 또는 SpannableStringBuilder 대신 일반 텍스트를 사용할 때 나타나는 것과 같은 일반 텍스트 선택 기능을 어떻게 얻을 수 있는지 궁금합니다. (나는 둘 다 시도했다) 평범한 텍스트를 사용한다면, 나는 어떤 단어의 어떤 부분을 선택하여 거기에서 텍스트를 입력 할 수있다.
편집 1 텍스트 선택은 가로 모드로 작동하지만 세로로는 작동하지 않습니다. 그래서 코드는 어느 정도 유효합니다 ...
편집 2 실제로 텍스트 선택은 휴대 전화에서는 가로 모드로 작동하지만 에뮬레이터에서는 작동하지 않습니다.
BufferType.SPANNABLE을 사용해 보셨습니까? EditText 자체가 EDITABLE을 설정한다고 생각합니다. – Barak
두 가지 모두 시도했습니다. 그러나, 난 그냥 풍경 모드에서 작동하지만 초상화에서 작동 발견 ... Wierder와 wierder ... – NickLH
풍경 레이아웃이 전혀 다른가요? – Barak