如何以编程方式更改窗口小部件视图(按钮)的可见性 [英] How to change visibility of widget views(Buttons) programmatically Android
本文介绍了如何以编程方式更改窗口小部件视图(按钮)的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的android小部件中有两个按钮,我想在运行时更改那里的可见性,即如果本地数据库中不存在数据,我想隐藏一个按钮.
I have two buttons in my android widget and I want to change there visibility at run time i.e. if data is not coming present in local database I want to hide one button.
如何获取该按钮的ID,以及如何使其可见或不可见.
How can I get the id's of that button and how can I make it visible or invisible.
请提出建议
推荐答案
您不能像这样更改可见性:
You can not change the visibility like:
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button"/>
View button = findViewById(R.id.button);
button.setVisibility(View.GONE);
您必须像这样获得按钮视图
You have to get the button view like
RemoteViews.findViewById(R.id.button, Visibility.GONE);
这篇关于如何以编程方式更改窗口小部件视图(按钮)的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文