Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7157859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T12:57:46+00:00 2026-05-28T12:57:46+00:00

I have a custom button in an activity. It works fine. I hit back,

  • 0

I have a custom button in an activity. It works fine. I hit back, then restart the activity, and the button is gone. I created a stripped project to show what the problem is.

The application starts with this activity (just a button that starts Activity2):

public class TestCustomButtonActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btn1 = (Button) findViewById(R.id.button1);
        btn1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                Intent intent = new Intent(TestCustomButtonActivity.this, Activity2.class);
                startActivity(intent);
                }
        });
    }
}

Activity2 has only one button

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/menu_left_button" />

menu_left_button is the xml selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
          android:constantSize="true">
    <item android:state_pressed="true"
          android:drawable="@drawable/button_left_pressed" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@drawable/button_left_hovered" /> <!-- focused -->
    <item android:drawable="@drawable/button_left_normal" /> <!-- default -->
</selector>

And that’s all there is to it. You start the application and hit button1, and you are presented with Activity2 and our custom button. And it works fine. But if you hit the back button (close Activity2) and hit button1 again, our custom button is not there! It has disappeared. Any good reason for that?

Target api level is 4 (if this has something to do with it).

Activity2 code is nearly empty:

public class Activity2 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act2);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T12:57:47+00:00Added an answer on May 28, 2026 at 12:57 pm

    After several months as you can see, I found the answer to this, by chance. It is posted as an answer in another stackoverflow question : ImageButton does not display a particular drawable. The actual problem as i now know is that the image “button_left_normal” does not show, since it is the first image alphabetically. If the button had a fixed size and not “wrap_content” as dimensions, i would be able to click it, and see that “button_left_pressed” is shown without any problem. I hope this helps someone out there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a default style for a Button including a custom ControlTemplate like
I have created a custom Button as follows. file : buttoncontrol.xml <?xml version=1.0 encoding=utf-8?>
I have a sheet with a custom button on it from where I control
I have a custom ButtonUI class that paints the button. Before drawing the text,
I have to create a custom compound button bar control in Android like the
I have a custom control that displays a tryAgain button when the control is
i have a custom cell i want to delete it when a button is
I have a custom keyboard and whenever I touch the backspace button for the
I have a custom UITableViewCell which contains several UIButtons. Each button's frame position is
I'm trying to create a custom control - a button - which will have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.