There is virtually no difference between a Button
and a TextView
. Button
is extended from a TextView
only. You can clear your doubt if you look at the source code of Button
public class Button extends TextView {
public Button(Context context) {
this(context, null);
}
public Button(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.buttonStyle);
}
public Button(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(event);
event.setClassName(Button.class.getName());
}
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(Button.class.getName());
}
}
EDIT:
But if you just want to change the background color of the Button
without changing the default style, you can do something like below,
btnName.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));
Remember to remove the android:background=""
or android:src=""
from your Button
if any in xml file.
This code only changes the background color without affecting the default style. You can change the background color with the standard HEX color codes.
reference
Standard Android Button with a different color