1. Are you ready for the Galaxy S20? Here is everything we know so far!

Text View Change Color

Discussion in 'Android Development' started by esirahimian, Jul 23, 2019.

  1. esirahimian

    esirahimian Lurker
    Thread Starter

    hello i have a text view and that text is winter is coming text view Color is green also i have a sound, and my sound to say "winter is coming" when sound is playing every word changes color with my sound example when my sound say winter , winters text color change to red


    Code (Java):
    1. <TextView
    2.     android:layout_width="wrap_content"
    3.     android:layout_height="wrap_content"
    4.     android:text="Winter Is Coming"
    5.     android:id="@+id/txt"
    6.     app:layout_constraintBottom_toBottomOf="parent"
    7.     app:layout_constraintLeft_toLeftOf="parent"
    8.     app:layout_constraintRight_toRightOf="parent"
    9.     app:layout_constraintTop_toTopOf="parent" />
    10.     <TextView
    11.         android:layout_width="wrap_content"
    12.         android:layout_height="wrap_content"
    13.         android:id="@+id/time"
    14.         android:text="..."/>
    15.     android:id="@+id/btn"
    16.     android:layout_width="wrap_content"
    17.     android:layout_height="wrap_content"
    18.     android:text="Play"
    19.     tools:layout_editor_absoluteX="147dp"
    20.     tools:layout_editor_absoluteY="419dp" />
    21.  
    22.  
    23.  
    24.  
    25. Button btn;
    26. TextView txt;
    27. MediaPlayer ply;
    28.     @Override
    29.     protected void onCreate(Bundle savedInstanceState) {
    30.         super.onCreate(savedInstanceState);
    31.         setContentView(R.layout.activity_main);
    32.         btn = findViewById(R.id.btn);
    33.         txt = findViewById(R.id.txt);
    34. btn.setOnClickListener(new View.OnClickListener() {
    35.     @Override
    36.     public void onClick(View view) {
    37.  
    38.         txt.setText("Winter is Coming".toString());
    39.         final MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.winter);
    40.         mp.start();
    41.         txt.setTextColor(Color.parseColor("#76FF03"));
    42.  
    43.     }
    44. });
    45.         new CountDownTimer(4, 1) {
    46.             @Override
    47.             public void onTick(long l) {
    48.                 txt.setTextColor(Color.parseColor("#76FF03"));
    49.             }
    50.  
    51.             @Override
    52.             public void onFinish() {
    53.  
    54.             }
    55.         };
    56.     }}
     


  2. 23tony

    23tony Well-Known Member

    You didn't really state a question, so I'm not sure what you want here; but if you're asking how to make it change color with every word, my first thought would be to make every word a separate audio file and play them in sequence, changing colors as you fire off each.
     
Loading...
Similar Threads - Text View Change
  1. Rajkumar Wadi
    Replies:
    4
    Views:
    111
  2. Beadmaster
    Replies:
    8
    Views:
    380
  3. Doulos Adonai
    Replies:
    1
    Views:
    309
  4. AndroidGUIIsComplicated
    Replies:
    1
    Views:
    429
  5. Tharpebb63
    Replies:
    1
    Views:
    273
  6. AndroidGUIIsComplicated
    Replies:
    0
    Views:
    469
  7. Rgarner
    Replies:
    32
    Views:
    849
  8. Haley Slaughter
    Replies:
    4
    Views:
    320
  9. Cinemato
    Replies:
    0
    Views:
    407
  10. jshoe22
    Replies:
    0
    Views:
    640

Share This Page

Loading...