2

When using the custom view, it seems that the android namespace attr extend from parent view can't be use. I think it not reasonable. Here is my code:

int[] set = {
    android.R.attr.src // idx 0 use the android: tag attr
};
final TypedArray b = getContext().obtainStyledAttributes(attrs, set);
BitmapDrawable drawable1 = (BitmapDrawable)b.getDrawable(0);
mIconBitmap = drawable1.getBitmap();
b.recycle();

and the activity is:

<com.example.ling.fragmenttest.TabImage
    xmlns:tabImage="http://schemas.android.com/apk/res/com.example.ling.fragmenttest"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/button_image"
    tabImage:tabColor="#FF33B5E5"
    tabImage:tabSrc="@drawable/ic_friend"
    android:src="@drawable/ic_setting"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_gravity="center_vertical"/>

I just want to use the android:src attr in java file. But the getDrawable() return null instead of ic_setting. By the way, my view is extend from ImageView.

I find one similar with my situation:[How to use standard attribute android:text in my custom view? But why I get the null.....Please help me out~

Community
  • 1
  • 1
Ling Qin
  • 21
  • 1

0 Answers0