https://androman.tistory.com/91
[Android] 안드로이드 Alert 창 띄우기
안녕하세요 오늘은 안드로이드에서 Alert 창을 띄어보겠습니다. Alert 띄우기 1. Empty Activity로 새로운 project 생성 2. 프로젝트 layout 지정 Button을 지정해서 화면 중앙으로 끌고 옵니다. 우측에 보이는
androman.tistory.com
[Android]setText()에 개행(엔터), 태그 넣기
자바코드(activity)에서 setText()로 값 변경시 태그넣기 TextView t1 = (TextView)findViewById(R.id.t1); t1.setText(Html.fromHtml("1번째줄" + " " + "2번째줄"));
blog.opid.kr
https://itpangpang.tistory.com/278
TextView 특정문자열 색깔넣기(setSpan, html)
TextView 특정문자열 색깔넣기(setSpan, html) ㆍ 이번글에서는 TextView 안에 있는 문자열중에 원하는 문자열만 색깔을 넣거나 바꾸는 방법에 대해 알아보도록 하겠습니다. ㆍ 가장 대중적인 방법인 setS
itpangpang.tistory.com
https://velog.io/@thevlakk/Android-AlertDialog-%EA%BE%B8%EB%A9%B0%EB%B3%B4%EA%B8%B0
[Android] AlertDialog Custom, 전부 커스텀
디자인이 나왔는데 dialog가 안드로이드의 기본 AlertDialog형태지만 폰트, 색상, 크기가 달라 커스텀을 해야했다. 이놈의 dialog들은 커스텀하기가 커스텀 뷰보다 힘든듯, 특히나 AlertDialog는 너무 꼭
velog.io
위 포스트들을 참조했습니다.
알림창을 만들어서 사용자에게 특정 내용을 안내할 일이 생겼다.
그리고 특정 문장에 색을 입히고 싶었다.
다음은 알림창을 만드는 방법이다.
// 알림창 조립, 제목, 내용
AlertDialog.Builder myBuilder = new AlertDialog.Builder(context);
myBuilder.setTitle("알림창 제목");
myBuilder.setMessage("메세지");
// 확인 버튼 만들기, 클릭 리스너로 특정 행동을 수행할 수 있음
myBuilder.setPositiveButton("확인", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 앱 상세창으로 이동
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", context.getPackageName(), null);
intent.setData(uri);
context.startActivity(intent);
}
});
// 취소 버튼 만들기
myBuilder.setNegativeButton("취소", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "취소 버튼을 누름.", Toast.LENGTH_SHORT).show();
}
});
// 알림창 보여주기
AlertDialog myAlert = myBuilder.show();
// 알림창 내용 받아오기
TextView textView = (TextView) myAlert.findViewById(android.R.id.message);
// 내용에 html 으로 작성 <br>로 줄 바꿈
String strFront = "이것은 알림창 내부 글입니다." +"<br><br>";
String strChange = "<font color=\"#D81B60\"><big><b>※ 이 문장만 색이 입혀지고 텍스트 사이즈가 크고 볼드체입니다..<b><big></font>";
// html 텍스트를 넣기
textView.setText(Html.fromHtml(strFront + strChange, 1));
// 내용 문장의 기본적인 텍스트 크기 설정
textView.setTextSize(11.0f);
myBuilder.setMessage("메세지"); 는 알림창 내부 내용을 생성하기 위해 작성했다.
메세지가 생성이되어야 받아올 수 있음.
실행해보면 다음과 같이 알림창이 생성되는 것을 볼 수 있다.
알림창 내부를 html이 아닌 setMessage 로 만으로 한다면 특정 텍스트만 색을 입히는 것은 불가능
'Develop > Android' 카테고리의 다른 글
[Android] context.getresources().getidentifier() 가 뭔가요? (0) | 2023.10.27 |
---|---|
[Android] 인앱 결제 시스템 만들기 (PBL v6, 비소비성 결제) (1) | 2023.10.25 |
[Android, Unity] 안드로이드 앱이 외부 앱에서 자신의 개별 저장소에 임시로 접근할 수 있도록 하기 (FileProvider, 임시 권한 주기) (0) | 2023.07.05 |
[Android] REQUEST_INSTALL_PACKAGES 권한 요청하기 (0) | 2023.06.23 |
[Android] An exception has occurred in the compiler (1.8.0_202) (0) | 2023.06.21 |