Skip to content

Instantly share code, notes, and snippets.

@ahmadmust8
Last active September 24, 2016 16:08
Show Gist options
  • Save ahmadmust8/cb499d7a220791222821b6feadb291e2 to your computer and use it in GitHub Desktop.
Save ahmadmust8/cb499d7a220791222821b6feadb291e2 to your computer and use it in GitHub Desktop.
simple App it is change text color
// see http://imgur.com/a/cjk7N
package com.ahmad.mustafa.exercises;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button blue =(Button) findViewById(R.id.Blue_Button);
blue.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
buttonClicked(v);
}
});
Button green = (Button)findViewById(R.id.Green_Button);
green.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
buttonClicked(v);
}
});
Button red = (Button)findViewById(R.id.Red_Button);
red.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
buttonClicked(v);
}
});
}
protected void buttonClicked(View view)
{
TextView o = (TextView)findViewById(R.id.o_TextView);
switch (view.getId()){
case (R.id.Blue_Button) :
o.setTextColor(Color.BLUE);
break;
case (R.id.Green_Button) :
o.setTextColor(Color.GREEN);
break;
case (R.id.Red_Button) :
o.setTextColor(Color.RED);
break;
default:
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment