我正在使用自定义吐司,nth
和ImageView
使用drawable中的背景。但Android Studio告诉我使用单个TextView
和复合可绘制。我已经使用了drawable作为背景,但是我怎样才能画出"相对于TextView
的某个位置的图片?
答案 0 :(得分:0)
您可以像这样使用单个TextView
和CompoundDrawable
Toast toast = Toast.makeText(this, "Custom Compount Drawable Toast", Toast.LENGTH_LONG);
View toastView = toast.getView(); //This'll return the default View of the Toast.
TextView toastMessage = (TextView) toastView.findViewById(android.R.id.textview);
toastMessage.setTextSize(25);
toastMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.image_id, 0, 0, 0);
toastMessage.setGravity(Gravity.CENTER);
toastMessage.setCompoundDrawablePadding(16);
toastView.setBackgroundColor(Color.CYAN);
toast.show();