audio.mp3正在播放时,Textview会突出显示

时间:2016-11-22 06:47:43

标签: android-studio

我在textview中有抒情。还有一个播放音频文件的按钮。但我想知道当我们点击播放按钮时我们如何突出显示textview字。

MediaPlayer播放;

TextView textView4;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_third_kalma);
    Button button = (Button) findViewById(R.id.btn4);

    if (play.isPlaying()) {

        textView4.setTextColor(ContextCompat.getColor(this, R.color.black));
    }

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent p = new Intent(Third.this,ThirdT.class);
            startActivity(p);
        }
    });

    play = MediaPlayer.create(this , R.raw.audio3);
    Button bone = (Button) findViewById(R.id.btnSec);
    bone.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {


            play.start();
        }});}

1 个答案:

答案 0 :(得分:0)

试试这段代码,会有所帮助: 尝试将此代码保留在计时器或调度程序中:

MediaPlayer mediaPlayer;
mediaPlayer = MediaPlayer.create(this, R.raw.sound);
if (mediaPlayer.isPlaying()){
mTextView.setTextColor(Color.parseColor("#Your own color code(#ff0000)")); 
}

或者你可以试试这个:

final Button play= (Button) findViewById(R.id.button_id);
        play.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                mTextView.setTextColor(Color.parseColor("your color code"));
            }
        });

或者您可以尝试调度程序,如:

ScheduledThreadPoolExecutor scheduler =
                (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(5);
        scheduler.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                if (mediaPlayer.isPlaying()){
                    mTextView.setTextColor(Color.parseColor("#Your own color code(#ff0000)")); 
                    }
                    }
        }, 0, 2, TimeUnit.SECONDS);