安卓:进行更改到按钮的父视图 [英] Android: Making changes to a button's parent view

查看:181
本文介绍了安卓:进行更改到按钮的父视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有里面一个按钮RelativeLayout的。一旦用户点击该按钮,我想更改父视图(RelativeLayout的)的背景。我知道我可以通过存储在变量父视图或按钮设置变量做到这一点,但我石灰,以避免(我有很好的理由不想要这个)。是不是有办法刚刚从按钮本身访问父视图?

I have a RelativeLayout with a button inside it. Once the user clicks on that button, I would like to change the background of the parent view (RelativeLayout). I know I can do this by storing the parent view in a variable or setting a tag on the button, but I'd lime to avoid that (I have very good reasons for not wanting this). Isn't there a way to just access the parent view from the button itself?

推荐答案

尝试<一href="http://developer.android.com/reference/android/view/View.html#getParent%28%29"><$c$c>View.getParent():

Button yourBtn = (Button) findViewById(R.id.your_btn);
RelativeLayout yourRelLay = (RelativeLayout) yourBtn.getParent();

这篇关于安卓:进行更改到按钮的父视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆