Android selectableItemBackground的代码实现

2019年10月10日15:27:31 Comment 1,001

Android selectableItemBackground的代码实现

Android xml文件中android:background="?attr/selectableItemBackground"代码实现为:

//5.0以上系统判断
if (Build.VERSION.SDK_INT >= 21) {
    int[] attrs = {android.R.attr.selectableItemBackground};
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs);
    int resourceId = typedArray.getResourceId(0, 0);
    textView.setBackgroundResource(resourceId);
}
  • 我的微信
  • 一起交流技术
  • weinxin
  • 我的微信公众号
  • 一起交流技术
  • weinxin

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: