Android复合drawable

时间:2016-01-11 07:34:39

标签: android drawable

我正在使用自定义吐司,nthImageView使用drawable中的背景。但Android Studio告诉我使用单个TextView复合可绘制。我已经使用了drawable作为背景,但是我怎样才能画出"相对于TextView的某个位置的图片?

1 个答案:

答案 0 :(得分:0)

您可以像这样使用单个TextViewCompoundDrawable

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();