3
android:background="?android:attr/selectableItemBackground""
을 프로그래밍 방식으로 어떻게 할 수 있습니까?? android : attr/프로그래밍 방식으로
mView.setBackgroundResource(android.R.attr.selectableItemBackground);
을 시도했지만 작동하지 않았습니다.
android:background="?android:attr/selectableItemBackground""
을 프로그래밍 방식으로 어떻게 할 수 있습니까?? android : attr/프로그래밍 방식으로
mView.setBackgroundResource(android.R.attr.selectableItemBackground);
을 시도했지만 작동하지 않았습니다.
먼저 속성을 해결해야합니다.
TypedValue typedValue = new TypedValue();
// I used getActivity() as if you were calling from a fragment.
// You just want to call getTheme() on the current activity, however you can get it
getActivity().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
// it's probably a good idea to check if the color wasn't specified as a resource
if (typedValue.resourceId != 0) {
mView.setBackgroundResource(typedValue.resourceId);
} else {
// this should work whether there was a resource id or not
mView.setBackgroundColor(typedValue.data);
}
예상대로 작업 해 주셔서 감사합니다. –