일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- ASMR
- 넷플릭스
- Firebase
- 이모지
- Linux
- 1인개발자
- Android
- 파이썬
- 장자명언
- 명언모음
- 벤자민플랭클린
- 코틀린
- Coroutine
- Freesound
- jetpack compose
- Streaming
- 공부집중
- 공자명언
- bash
- 좋은글필사하기
- 명심보감
- 오픈소스
- 이모지메모
- androidx
- FSM
- DART
- Flutter
- kotlin
- recyclerview
- 소울칼리버6
Archives
- Today
- Total
Vintage appMaker의 Tech Blog
Android Toast 중복방지 본문
Toast를 안드로이드에서 메시지 용도로 사용하다보면 요청한 만큼 실행되는 경우가 발생한다. 논리적으로는 맞지만 사용자 측면에서는 불편할 수 있기에 Toast 중복을 막아야 하는 경우가 발생한다.
원본링크:
https://anhana.tistory.com/19
Toast 메시지 중복방지.
안녕하세요. 하나아빠 입니다. ㅎㅎ Toast 는 안드로이드 개발시에 유용하게 사용되는 간단한 팝업 메시지 인데요. 사용방법은 아래와 같습니다. 1 Toast.makeText(getBaseContext(), "Toast Message", Toast.L..
anhana.tistory.com
커스틈 Toast를 사용할 경우가 많아서, 수정하여 활용한 코드
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#00000000"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
card_view:cardBackgroundColor="#EDEFEF"
android:layout_marginTop ="4dp"
android:layout_marginLeft ="15dp"
android:layout_marginRight ="15dp"
android:layout_marginBottom ="4dp"
card_view:cardCornerRadius="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:weightSum="1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.vanniktech.emoji.EmojiTextView
android:textColor="@color/colorCardText"
android:textSize="20sp"
android:layout_margin="5dp"
android:paddingLeft="10dp"
android:id="@+id/txtDescription"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
[custom_emoti_toast.xml]
var toast : Toast? = null
fun showCustom( c : Context, s : String) {
val layoutInflater =
c.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val layout = layoutInflater.inflate(R.layout.custom_emoti_toast, null)
// layout 안의 txtMessage
// toast에서는 com.vanniktech.emoji.EmojiTextView 캐스팅에러 발생함
// TextView로 설정했던 것을 com.vanniktech.emoji.EmojiTextView로 변경함.
// XML 캐쉬버그로 예상함.
layout.txtDescription.text = s
if (toast == null ) {
toast = Toast(c)
}
toast?.setGravity(Gravity.TOP, 0, 0)
toast?.duration = Toast.LENGTH_SHORT
toast?.view = layout
toast?.show()
}
[Util.kt]
정리한 페이지
Android Toast 중복방지 | 메모광
메모광 > 프로그래밍 > Android > Android Toast 중복방지 Android Toast 중복방지 adsloader 2020년 8월 10일
vintageappmaker.com
'Source code or Tip > Android(Java, Kotlin)' 카테고리의 다른 글
[kotlin] RecyclerView full size capture - 코틀린 변환 (0) | 2020.08.16 |
---|---|
[Link] Android Bitmap에 워터마크 추가하기 (0) | 2020.08.12 |
[Android] appBook source (0) | 2020.07.20 |
JavaToKotlin (0) | 2020.07.18 |
Firebase Template with kotlin (0) | 2020.07.18 |
Comments