How to set a button visible from another activity in android

前端 未结 3 1042
北恋
北恋 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:39

    Try this code in onResume() of your MainActivity:

     try {
         if(getIntent().getExtras().containsKey("your_parameter")) {
             btn.setVisibility(View.VISIBLE);
         }
     } catch(Exception e){
         //...
     }
    

    In second Activity put "your_parameter" parameter as extra to Intent only if you want to make that button visible.

提交回复
热议问题