0
0
lhm 3 роки тому
батько
коміт
c7ba12ec39

+ 16 - 0
app/src/main/java/com/emato/ich/utils/ButtonUtils.java

@@ -0,0 +1,16 @@
+package com.emato.ich.utils;
+
+public class ButtonUtils {
+
+    private static long lastClickTime;
+
+    public synchronized static boolean isFastClick() {
+        long time = System.currentTimeMillis();
+        if (time - lastClickTime < 500) {
+            return true;
+        }
+        lastClickTime = time;
+        return false;
+    }
+
+}

+ 40 - 0
app/src/main/java/com/emato/ich/utils/ToastUtils.java

@@ -0,0 +1,40 @@
+package com.emato.ich.utils;
+
+import android.content.Context;
+import android.os.Handler;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.emato.ich.R;
+
+public class ToastUtils {
+
+    private static Toast mToast;
+    private static Handler mHandler = new Handler();
+    private static Runnable runnable = new Runnable() {
+        public void run() {
+            mToast.cancel();
+            //toast隐藏后,将其置为null
+            mToast=null;
+        }
+    };
+
+    public static void make(Context context, String msg) {
+        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        //自定义布局
+        View view = inflater.inflate(R.layout.custom_toast, null);
+        TextView text = (TextView) view.findViewById(R.id.toast_message);
+        //显示的提示文字
+        text.setText(msg);
+        mHandler.removeCallbacks(runnable);
+        mToast = new Toast(context);
+        mToast.setDuration(Toast.LENGTH_SHORT);
+        mToast.setGravity(Gravity.CENTER, 0, -22);
+        mToast.setView(view);
+        mToast.show();
+    }
+
+}

+ 11 - 0
app/src/main/res/drawable/toast_bg.xml

@@ -0,0 +1,11 @@
+<shape
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <!-- 填充的颜色 -->
+    <solid android:color="#000000" />
+    <!-- 弧形的半径 -->
+    <corners android:radius="20dp" />
+    <!-- 边框的颜色及粗细 -->
+<!--    <stroke android:color="#000"-->
+<!--        android:width="4dp"/>-->
+</shape>

+ 17 - 0
app/src/main/res/layout/custom_toast.xml

@@ -0,0 +1,17 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="35dp"
+    android:background="@drawable/toast_bg"
+    android:padding="10dp" >
+    <TextView
+        android:id="@+id/toast_message"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:gravity="center"
+        android:maxLines="2"
+        android:textColor="#fff"
+        android:textSize="14sp"
+        android:paddingLeft="5dp"
+        android:paddingRight="5dp"
+        android:text=""/>
+</RelativeLayout>