Android

showToast : Toast Custom

그란. 2019. 4. 19. 20:00

 

 

 

 

toast_design

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/toast_design_root">

    <TextView
        android:id="@+id/TextView_toast_design"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25dp"
        android:textColor="@color/app_black"
        android:background="@drawable/toast_design_bg" />
</LinearLayout>

 

 

@drawable/toast_design_bg

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <stroke
        android:width="3dp"
        android:color="#BDBDBD" />
    <solid
        android:color="@color/app_light_grey" />
    <padding
        android:left="20dp"
        android:bottom="20dp"
        android:right="20dp"
        android:top="20dp" />
    <corners
        android:radius="15dp" />
</shape>

 

 

사용 (BaseActivity)

public void showToast(String message) {

        LayoutInflater inflater = getLayoutInflater();
        View toastDesign = inflater.inflate(R.layout.toast_design, findViewById(R.id.toast_design_root));

        TextView text = toastDesign.findViewById(R.id.TextView_toast_design);
        text.setText(message);

        Toast toast = new Toast(this);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(toastDesign);
        toast.show();
    }

'Android' 카테고리의 다른 글

RxJava 소스 모음  (0) 2019.06.15
Room Library  (0) 2019.05.21
도로명 주소 입력 받기 ( WebView + JS 연결)  (0) 2019.04.19
RecyclerView SwipeToDelete  (0) 2019.04.19
ScrollView PullToRefreshLayout  (0) 2019.04.19