0
android.widget.Button
을 기반으로 자신 만의 버튼을 만들려고합니다. XML에서프로그래밍 방식으로 스타일 속성을 설정할 때 현재 테마에서 스타일 'My_Button'을 찾지 못했습니다.
그러나 설정 스타일 작품 현재 테마에서 스타일 'my_button이라는'를 찾는 데 실패
: 나는 프로그래밍 스타일 속성을 설정하지만,이 렌더링 문제를 얻고있다.
오전 내가 모르는 뭔가가?
P/s : 영어는 제 모국어가 아닙니다. 제발 착오를 저 지르십시오.
activity_main.xml
<com.myapp.Components.Button android:id="@+id/xx" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="touch_" app:_icon=""/> <com.myapp.Components.Button style="@style/My_Button" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="touch" app:_icon=""/>
Button.java
public class Button extends android.widget.Button { public Button(@NonNull Context context) { super(context, null, R.style.My_Button); init(context, null); } public Button(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs, R.style.My_Button); init(context, attrs); } public Button(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, R.style.My_Button); init(context, attrs); } // ... more }
,styles.xml
<style name="My_Button" parent="Base.Widget.AppCompat.Button.Borderless"> <item name="android:foreground">?android:attr/selectableItemBackground</item> <item name="android:background">#592612</item> <item name="android:gravity">center</item> </style>