Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Android Timer
- 백엔드 포지션 변경
- 운영체제 공룡책
- 운영체제 다중모드
- 백엔드 직무 변경
- 운영체제 멀티 태스킹
- 운영체제 자원관리
- 운영체제 커널모드
- spring paging sort sql injection
- spring dynamic query sql injection
- spring 동적 쿼리 주의사항
- aws ec2 scp 파일 전송
- 운영체제 작동방식
- android 타이머
- ec2 scp 파일 전송
- spring exception stackTrace remove
- spring sql injection 방지
- spring exception cause remove
- spring sql injection
- IT 포지션 변경
- OS 자원관리
- spring exceptionHandler response cause
- 개발 직무 변경
- 개발 포지션 변경
- spring responseEntity response stackTrace
- 운영체제 개념
- IT 직무 변경
- 운영체제 멀티 프로그래밍
- spring responseEntity response cause
- spring exceptionHandler reposnse stackTrace
Archives
- Today
- Total
오늘도 삽질중
android SpannableString을 사용해서 text 일부분만 컬러변경하기 본문
반응형
text 중에서 일부분만 컬러를 바꾸고 싶을 경우에 사용하시면 됩니다.
기초적인 틀만 잡혀있으니 다양하게 변형해서 사용하시길 바랍니다.
전체소스 및 결과화면입니다.
MainActivity.class
public class MainActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate( @Nullable Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
textView = findViewById( R.id.textview );
textView.setText( "hello Android" );
textFormColor( textView, textView.getText( ).toString( ), 2, 3 );
// 또는
// textFormColor( textView , "hello Android" ,2,3 );
}
/**
* @param v textview
* @param text string text
* @param left left color position
* @param right right color position
*/
public void textFormColor( View v, String text, int left, int right ) {
if ( text == null ) return;
if ( left < 0 || right < 0 ) return;
if ( text.length( ) < left + right ) return;
if ( v.getClass( ) == AppCompatTextView.class || v.getClass( ) == TextView.class ) {
SpannableString s = new SpannableString( text );
s.setSpan( new ForegroundColorSpan( Color.BLUE ), 0, left, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
s.setSpan( new ForegroundColorSpan( Color.RED ), text.length( ) - right, text.length( ), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE );
( ( TextView ) v ).setText( s );
}
}
}
반응형
'안드로이드' 카테고리의 다른 글
android compareTo (0) | 2020.02.03 |
---|---|
android intent 이메일 전송하기 (0) | 2019.09.20 |
android TimerView (0) | 2019.07.31 |
android ArrayList Collections.shuffle 시 주의해야 할 점 (비교값 중복) (0) | 2019.03.17 |
android String 배열 ArrayList 변환 (0) | 2019.03.17 |
Comments