Turning ImageButton to toggled one

Was trying to make ImageButton s “toglable”. Recipes are everywhere and I made such program: https://github.com/dims12/TryInvestigateButtonUnpress

It shows “pressed” button by

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ButterKnife.bind(this);

    someButton.setSelected(true);
}

And looks the following way:

xboofaf

Unfortunately, once I press “Home” button on the device, button turns unpressed. This happens even before application actually minimizes.

The solution for this appeared simple: I was to simulated toggle not with “pressed”, but with “selected” attribute.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s