change button text color when pressed

后端 未结 5 1341
情歌与酒
情歌与酒 2021-02-02 15:53

I have made my button transparent so I would like to have the button text color change when the button is pressed. Is it possible to do this using just xml files?

5条回答
  •  没有蜡笔的小新
    2021-02-02 16:29

    You have to do it in your code. Try this:

        mBtn = ((Button) findViewById( R.id.button1 ));
        mBtn.setOnClickListener( new OnClickListener() {
    
            @Override
            public void onClick(View v) {
                mBtn.setTextColor( Color.RED );
            }
        });
    

    Declare:

    private Button mBtn;
    

提交回复
热议问题