Access resource defined in theme and attrs.xml android

前端 未结 5 1959
情歌与酒
情歌与酒 2020-12-04 21:55

I have a scenario in which I want to set a Drawable depending upon the theme defined.

To explain this further, Here is what I have in code:

5条回答
  •  无人及你
    2020-12-04 22:48

    I think you can get the Drawable with this code:

    TypedArray a = getTheme().obtainStyledAttributes(R.style.AppTheme, new int[] {R.attr.homeIcon});     
    int attributeResourceId = a.getResourceId(0, 0);
    Drawable drawable = getResources().getDrawable(attributeResourceId);
    a.recycle();
    

提交回复
热议问题