Trying to set opacity (alpha) for a view in android

I am using a  button :
In my onCreate() event, I am calling Button01 like this:

View Button01 = this.findViewById(;
There is a background in the application, and I want to set an opacity on this submit button. How can I set an opacity for this view? Is it something that I can set on the java side, or can I set in the main.xml file?

On the java side I tried Button01.mutate().SetAlpha(100), but it gave me an error
Last updated:1/13/2016 11:24:57 PM

1 Answers

Anonymous User
Anonymous User

Hi Anurag,

You just need to extend TextView and override onSetAlpha:

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class AlphaTextView extends TextView {
  public AlphaTextView(Context context) {
  public AlphaTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
  public AlphaTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  public boolean onSetAlpha(int alpha) {
    return true;