Please let me know how I can set the default background for the desired button.
I mean ... I know that I can define the "style" that android sets: the background is "@null", and ask users to explicitly apply the style in their layout. For example:
<style name="MyButton" parent="@android:style/Widget.Button"> <item name="android:background">@null</item> </style>
and
<com.xxx.widget.MyButton android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/MyButton" android:text="MyButton" />
The code works well. But how can I apply this style in my "MyButton" class internally and let users not set the style explicitly?
For example, how to make the following layout work as before:
<com.xxx.widget.MyButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="MyButton" />
I tried to do this in the constructor as shown below, but it doesn't work.
public MyButton(Context context, AttributeSet attrs) { this(context, attrs, com.xxx.R.style.MyButton); }
PS. I want to apply this "zero" background when the user does not set the background explicitly.
Henry
source share