728x90
반응형
SMALL
토스트 (Toast)
토스트 (Toast)는 사용자에게 짧은 메시지 형식으로 정보를 전달하는 팝업을 의미한다.
xml : drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="30dp"
/>
<solid
android:color="#A19CFF"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="150dp"
android:height="40dp"
/>
</shape>
xml : layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/toast_layout_root"
android:orientation="vertical">
<TextView
android:id="@+id/textboard"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:padding="20dp"
android:textSize="15sp"
android:gravity="center"
android:textColor="#FFFFFF"
android:background="@drawable/toast_shape"/>
</LinearLayout>
java
public void customToastView(String text){
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_board, (ViewGroup) findViewById(R.id.toast_layout_root));
TextView textView = layout.findViewById(R.id.textboard);
textView.setText(text);
Toast toastView = Toast.makeText(getApplicationContext(),text, Toast.LENGTH_SHORT);
toastView.setGravity(Gravity.BOTTOM,0,30);
toastView.setView(layout);
toastView.show();
}
728x90
반응형
LIST
'App Programming > Android Studio' 카테고리의 다른 글
[Android Studio] 하단 네비게이션 (Bottom Navigation) (0) | 2022.11.18 |
---|---|
[Android Studio] Intent (인텐트)로 값 전달하기 (0) | 2022.11.11 |
[Android Studio] TimePicker 색상 커스텀 (0) | 2022.11.04 |
[Android Studio] 버튼 클릭시 이미지 변경 (0) | 2022.11.04 |
[Android Studio] 투명도 (Opacity) (0) | 2022.11.04 |