項目快結束了,終于有空可以總結下在開發中遇到的一些問題。
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:主機域名、網絡空間、營銷軟件、網站建設、紅古網站維護、網站推廣。需要在文字的左側顯示圖片 效果圖如下:
用了兩種方式實現:
一、自定義
1、新建一個xml布局 item_toast:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RelativeLayout android:layout_width="wrap_content" android:layout_height="50dp" android:orientation="horizontal" android:paddingRight="10dp" android:paddingLeft="10dp" android:background="@drawable/toast_bg" android:gravity="center" > <ImageView android:id="@+id/img_hint" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true"/> <TextView android:id="@+id/tv_hint" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@+id/img_hint" android:layout_marginLeft="5dp" android:text="TextView" android:textSize="17sp" android:textColor="@color/white" /> </RelativeLayout> </RelativeLayout>
其中 android:background="@drawable/toast_bg" 為Toast帶圓角的背景
2、在代碼中實現。
//帶圖片的Toast public static void ToastWithPicture(Activity context, String str,int drawable) { if(toast != null){ toast.cancel(); } View view = context.getLayoutInflater().inflate(R.layout.item_toast, null); TextView tv_hint = (TextView) view.findViewById(R.id.tv_hint); ImageView img_hint = (ImageView) view.findViewById(R.id.img_hint); tv_hint.setText(str); img_hint.setImageResource(drawable); toast = new Toast(context); toast.setGravity(Gravity.TOP, toast.getXOffset() / 2, 120); toast.setDuration(0); toast.setView(view); toast.show(); }
由于項目中需要用到Toast的地方非常多,所以我把它封裝成一個方法,放在Utility類中。需要時直接調用就可以啦。
Utility.ToastWithPicture(this, getResources() .getString(R.string.hint_talk_unlock),R.drawable.img_unlock);
二、不需要新建xml文件
//帶圖片的Toast public static void ToastWithPicture(Activity context, String str,int drawable) { if(toast != null){ toast.cancel(); } ImageView p_w_picpathView = new ImageView(context); p_w_picpathView.setImageResource(drawable); toast = Toast.makeText(context, str, Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP, toast.getXOffset() / 2, 120); LinearLayout view = (LinearLayout) toast.getView(); view.setOrientation(LinearLayout.HORIZONTAL); view.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); //設置字體大小 TextView msgText = (TextView) view.getChildAt(0); msgText.setTextSize(17); view.addView(p_w_picpathView, 0); toast.show(); }
但是這種方法好像沒辦法讓文字和圖片居中對齊。
另外有需要云服務器可以了解下創新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
本文名稱:帶圖片的Toast-創新互聯
標題URL:http://vcdvsql.cn/article40/cssheo.html
成都網站建設公司_創新互聯,為您提供網站策劃、域名注冊、App設計、移動網站建設、靜態網站、ChatGPT
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯