How to set a button visible from another activity in android

前端 未结 3 1040
北恋
北恋 2021-01-25 03:19

I have a very simple problem. I have a invisible button in my Main Activity, and I have a second Activity that makes that button visible. In the second activity I don´t have a p

3条回答
  •  粉色の甜心
    2021-01-25 03:36

    Solve the problem. In the second Activity a have a static boolean variable that begins false. Once the oncreate() in the second Activity is call, the boolean variable is change to true. onresume() in MainActivity i check if the boolean variable is true, and change the visibility of the button.

    SecondActivity

    public static boolean showButton = false;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showButton = true;
    
    }
    

    MainActivity

    @Override
    protected void onResume() {
        if ( Display.showButton){
            mMyButtonToBeHidden.setVisibility(View.VISIBLE);
        }
        super.onResume();
    } 
    

提交回复
热议问题