开发者

Get reference of one Activity from another in android

开发者 https://www.devze.com 2023-03-20 11:57 出处:网络
How can i get reference to another activity, because i have placed an ActionBar in main activity say ActivityA, this ActionBar is visible on all other activities as well, nowi want to access this Line

How can i get reference to another activity, because i have placed an ActionBar in main activity say ActivityA, this ActionBar is visible on all other activities as well, now i want to access this LinearLayout and make it hidden from ActivityB.

I want to do somthing like this.

LinearLayout bar = (LinearLayout) ActivityA.findViewById(R.id.actionbarhome);
bar.setVisibility(LinearLayout.GONE);

What should be there in place of ActivityA? Any help would be开发者_JAVA技巧 appreciated.


You can inflate and grab the Layout of the ActivityA and then use findViewById to grab the Required LinearLayout e.g. :

LayoutInflater inflater = getLayoutInflater();
LinearLayout ll_ActivityA = (LinearLayout) inflater.inflate(R.layout.activity_a,null);
LinearLayout bar = (LinearLayout) ll_ActivityA.findViewById(R.id.actionbarhome);
bar.setVisibility(LinearLayout.GONE);


There is a tutorial in the doc about removing the action bar for a particular activity.

0

精彩评论

暂无评论...
验证码 换一张
取 消