魅族手機遇到修改Toast樣式BUG

來源:互聯網
上載者:User

標籤:

因為測試是個魅族手機出現各種bug記錄下。

需求是這樣


為了 和原生toast保持一致 不修改為自訂Toast 而是在原生上修改,按下面代碼

public static void showMyToast(Activity context, String maney,String...content ){Toast toast = Toast.makeText(context,content[0], Toast.LENGTH_SHORT);LinearLayout toastView = (LinearLayout) toast.getView();TextView tv = new TextView(context);LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);params.gravity =Gravity.CENTER_HORIZONTAL;View view = toastView.findViewById(android.R.id.message);TextView tv_toast = null ;ColorStateList color =null;float tv_toast_size = 0;if(view != null ){tv_toast = (TextView) view;color = tv_toast.getTextColors();tv_toast_size = tv_toast.getTextSize();tv.setTextColor(color);}TextView tv2 =null;if (content.length>1) {tv2 = new TextView(context);toastView.addView(tv2,params);tv2.setText(content[1]);tv2.setTextColor(color);tv2.setTextSize(TypedValue.COMPLEX_UNIT_PX,tv_toast_size);}tv.setText(maney);        Drawable drawable= UIUtils.getDrawable(R.drawable.ic_dish_opu_money);        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());        tv.setCompoundDrawables(drawable,null,null,null);        toastView.addView(tv, 0,params);toast.show();}


魅族手機居然是這樣子顯示


public static void showMyToast(Activity context, String maney, String...content ){   Toast toast = Toast.makeText(context,content[0], Toast.LENGTH_SHORT);   LinearLayout toastView = (LinearLayout) toast.getView();   TextView tv = new TextView(context);   LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);   params.gravity =Gravity.CENTER_HORIZONTAL;      View view = toastView.findViewById(android.R.id.message);   TextView tv_toast = null ;   ColorStateList color =null;   Drawable bg_color =null;   float tv_toast_size = 0;   if(view != null ){      tv_toast = (TextView) view;      color = tv_toast.getTextColors();      tv_toast_size = tv_toast.getTextSize();      tv.setTextColor(color);      bg_color = tv_toast.getBackground();
      //關鍵代碼 因為魅族手機的是Toast的原有Textview背景色不為null toastlayout 背景色為null,而一般其他手機是相反的      if (bg_color!=null) {         toastView.setBackground(bg_color);         tv_toast.setBackground(null);      }   }   TextView tv2 =null;   if (content.length>1) {      tv2 = new TextView(context);      toastView.addView(tv2,params);      tv2.setText(content[1]);      tv2.setTextColor(color);      tv2.setTextSize(TypedValue.COMPLEX_UNIT_PX,tv_toast_size);   }   tv.setText(maney);       Drawable drawable= UIUtils.getDrawable(R.drawable.ic_dish_opu_money);       drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());       tv.setCompoundDrawables(drawable,null,null,null);       toastView.addView(tv, 0,params);   toast.show();}



魅族手機遇到修改Toast樣式BUG

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.