如何永远隐藏视图 [英] How to hide views for always

查看:86
本文介绍了如何永远隐藏视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何始终隐藏视图吗?

Can somebody tell me how to hide views for always?

我正在使用 view.setVisibility(view.GONE); 隐藏视图,但是当重新打开应用程序时,我必须重新隐藏该视图.我希望单击按钮时始终隐藏视图,直到清除应用程序数据或卸载为止.谢谢!

I'm hiding a view with view.setVisibility(view.GONE); but when reopen the app I have to re-hide the view. I want a view hide for always when button is clicked until clearing app data or uninstalling. Thanks!

推荐答案

没有永久隐藏的选项,但是您可以通过这种方式实现

There is not option to permanent hide but you can achieve by this way

1.通过

parent.removeViewAt(index);

parent.removeView(view);

  1. 您必须将状态保存到

  1. you have to save the state to show/hide the view on permanent storage like

共享首选项/数据库

共享首选项示例

1.将值存储在 sharedPrefernces 中:

SharedPreferences preferences = this.getSharedPreferences("SoldiPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("storevalue", false);
editor.commit();

2.从 sharedPreferences 中获取值:

SharedPreferences preferences = this.getSharedPreferences("SoldiPreferences", Context.MODE_PRIVATE);
preferences.getBoolean("storevalue", false);

if(preferences.getBoolean("storevalue", false))
{
view.setVisibility(View.VISIBLE);
}
else
view.setVisibility(View.GONE);

这篇关于如何永远隐藏视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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