自定義吐司
View view = View.inflate(this, R.layout.number_address_toast, null);//左邊是電話圖片,右邊是歸屬地資訊的佈局檔案
view.setBackgroundResource(bgs[numberAddressBgWhich]);//也可以是一個TextView,bgs是一個背景圖片的陣列 numberAddressBgWhich是從SharedPreferences裡讀取的
TextView tv_number_address = (TextView) view.findViewById(R.id.tv_number_address);
tv_number_address.setText(address);//設定右邊的歸屬地資訊
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
// 窗體的引數就設定好了
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.format = PixelFormat.TRANSLUCENT;
params.type = WindowManager.LayoutParams.TYPE_TOAST;
wm.addView(view, params);//引數一:自定義吐司裡要顯示的東西 引數二:窗體管理器
主要就是建立一個佈局,這個佈局可以是載入佈局檔案,也可是隻是一個TextView,然後用WindowManager.addView(view,params);即可 第二個引數就是窗體
佈局檔案:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_call" />
<TextView
android:id="@+id/tv_number_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="號碼歸屬地"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
相關文章
- 自定義View:自定義屬性(自定義按鈕實現)View
- 08.Django自定義模板,自定義標籤和自定義過濾器Django過濾器
- 自定義ImageView完成圓形頭像自定義View
- 自定義VIEWView
- 自定義圓環
- 自定義SnackBar
- 自定義useState
- 自定義_ajax
- 自定義Annotation
- 自定義OrderedMap
- 自定義 Drawable
- 自定義UICollectionViewLayoutUIView
- 自定義UITabBarUItabBar
- 自定義scrollbar
- 自定義Drawable
- 自定義ToastAST
- android自定義view(自定義數字鍵盤)AndroidView
- vue自定義全域性元件(或自定義外掛)Vue元件
- android自定義View&自定義ViewGroup(下)AndroidView
- android自定義View&自定義ViewGroup(上)AndroidView
- Android自定義控制元件——自定義屬性Android控制元件
- netty自定義Decoder用於自定義協議Netty協議
- 4. 自定義控制元件(4) --- 自定義屬性控制元件
- android自定義鍵盤 自定義身份證鍵盤Android
- Android自定義控制元件之自定義屬性Android控制元件
- GridView 自定義模版自定義修改,刪除,分頁View
- 自定義 Artisan 命令
- 自定義ClassLoader
- 自定義QTimeEditQT
- JavaScript自定義事件JavaScript事件
- 自定義註解
- Maven 自定義archeTypeMaven
- MySQL自定義排序MySql排序
- Flutter 自定義 TabBarFluttertabBar
- 自定義列舉
- 自定義LinkedList
- 自定義型別型別
- vue 自定義指令Vue