Reputation: 12615
I want to know how to change the properties of some view while another is being pressed?
for example a textview changes it's color while another button is being pressed?
Upvotes: 0
Views: 47
Reputation: 7141
It's just sample:
TextView txt1 = (TextView) findViewById(R.id.text1);
TextView txt2 = (TextView) findViewById(R.id.text2);
and one button
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener()
{
public void onClick(View back_button)
{
txt1.setBackgroundColor(Color.BLACK);
txt2.setBackgroundColor(Color.BLACK);
}});
Here when the button clicked the background color of the textview change to black. Try like this for other properties
Upvotes: 0
Reputation: 399
Here's a demo for you In java
name = (EditText) findViewById(R.id.editText1);
pwd = (EditText) findViewById(R.id.editText2);
sp=getSharedPreferences("userdata",MODE_PRIVATE);
speditor=sp.edit();
log = (Button) findViewById(R.id.button1);
log.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(name.getText().toString().isEmpty())
{
name.setBackgroundColor(Color.RED);
Toast.makeText(getBaseContext(), "Invalid Username !!! :", Toast.LENGTH_SHORT).show();
}
if((name.isFocusable()==true)||(pwd.isFocusable()==true))
{
name.setBackgroundColor(Color.WHITE);
pwd.setBackgroundColor(Color.WHITE);
}
if(pwd.getText().toString().isEmpty())
{
pwd.setBackgroundColor(Color.RED);
Toast.makeText(getBaseContext(), "Invalid Password !!! :", Toast.LENGTH_SHORT).show();
}
String n,p;
n=sp.getString("NAME","");
p=sp.getString("PASWRD","");
if((name.getText().toString().equals(n))&&(pwd.getText().toString().equals(p))){
Toast.makeText(getBaseContext(), "Welcome "+name.getText().toString(),Toast.LENGTH_LONG).show();
Intent nd=new Intent(getBaseContext(),DiaryActivity.class);
startActivity(nd);
}
}
});
reg = (Button) findViewById(R.id.button2);
reg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(name.getText().toString().isEmpty())
{
name.setBackgroundColor(Color.RED);
Toast.makeText(getBaseContext(), "Invalid Username !!! :", Toast.LENGTH_SHORT).show();
}
if((name.isFocusable()==true)||(pwd.isFocusable()==true))
{
name.setBackgroundColor(Color.WHITE);
pwd.setBackgroundColor(Color.WHITE);
}
if(pwd.getText().toString().isEmpty())
{
pwd.setBackgroundColor(Color.RED);
Toast.makeText(getBaseContext(), "Invalid Password !!! :", Toast.LENGTH_SHORT).show();
}
if((!pwd.getText().toString().isEmpty())&&(!name.getText().toString().isEmpty())){
speditor.putString("NAME",name.getText().toString());
speditor.putString("PASWRD",pwd.getText().toString());
speditor.commit();
Toast.makeText(getBaseContext(),"Hello "+name.getText().toString()+" You are Registered",Toast.LENGTH_LONG).show();
}
}
});
Upvotes: 0
Reputation: 2319
Register an OnTouchListener
for the View
which is pressed and change the TextView
's properties there in the onTouch
method.
Upvotes: 1