사용자 정의 버튼의 기본 배경을 null로 설정하려면 어떻게합니까? "@null"에 을 배경 및 명시 적으로 자신의 레이아웃에 스타일을 적용하도록 요청 :사용자 정의보기에서 기본 스타일 (속성) 제공
내 말은 ... 는 내가 안드로이드를 설정 "스타일"을 정의 할 수 있습니다 알고있다. 예를 들어 : 코드 위
<style name="MyButton" parent="@android:style/Widget.Button">
<item name="android:background">@null</item>
</style>
및
<com.xxx.widget.MyButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/MyButton"
android:text="MyButton" />
잘 노력하고 있습니다. 그러나 내 클래스 "MyButton"에서이 스타일을 내부적으로 적용하고 사용자가 스타일을 명시 적으로 설정하지 못하게하려면 어떻게해야합니까?
<com.xxx.widget.MyButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="MyButton" />
내가 다음과 같이 생성자에서이 작업을 수행하려고하지만 작동하지 :
예를 들어, 만드는 방법 레이아웃 다음은 이전과 같이 작동합니다.
public MyButton(Context context, AttributeSet attrs) {
this(context, attrs, com.xxx.R.style.MyButton);
}
ps. 사용자가 배경을 명시 적으로 설정하지 않은 경우이 "null"배경을 적용하려고합니다.
난 당신이 질문의 제목을 변경한다고 생각합니다. 기본 스타일은 언제든지 가질 수 있지만 나중에 변경할 수 있습니다. 아마도 당신은 '최종 스타일'또는 이와 비슷한 말을하기를 좋아할 것입니다. – ikbal
이것에 대한 몇 가지 팁은 http://stackoverflow.com/questions/4493947/how-to-define-theme-style-item-for-custom-widget을 참조하십시오. –
비슷한 요구 사항이 있음 : http://stackoverflow.com/questions/31504413/theme-style-for-custom-view/31505624#31505624 – stefan