I am having a button I want to do toggle on button like on and off,What I required is I am having two backgroundimages.
When I first time tap on button first background image should be done and on second time second background image should be changed like in toggle button.
Anybody please help me as I am new to android.
This is my activity:
public class MainActivity extends Activity {
private Button Button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button1 = (Button) findViewById(R.id.Button1);
Button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.setBackgroundResource(R.drawable.ic_launcher);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Thanks.