gpt4 book ai didi

android - 如何仅在第一个应用程序启动时打开 NavigationDrawer?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:09:20 27 4
gpt4 key购买 nike

根据 Google 指南,建议您仅在安装并打开应用程序后第一次打开 DrawerLayout(向用户展示功能)。

你会怎么做?

它似乎是 openDrawer() 方法与某种偏好的组合。

最佳答案

为此,我建议您使用SharedPreferences:

The basic idea is that you read the SharedPreferences and look for a boolean value that doesn't exist there at first app start. By default, you will return "true" if the value you were looking for could not be found, indicating that it is in fact the first app start. Then, after your first app start you will store the value "false" in your SharedPreferences, and upon next start, the value "false" will be read from the SharedPreferences, indicating that it is no longer the first app start.

下面是它的外观示例:

@Override
protected void onCreate(Bundle savedInstanceState) {
// your other code...
// setContentView(...) initialize drawer and stuff like that...

// use thread for performance
Thread t = new Thread(new Runnable() {

@Override
public void run() {

SharedPreferences sp = Context.getSharedPreferences("yoursharedprefs", 0);
boolean isFirstStart = sp.getBoolean("key", true);
// we will not get a value at first start, so true will be returned

// if it was the first app start
if(isFirstStart) {
mDrawerLayout.openDrawer(mDrawerList);
Editor e = sp.edit();
// we save the value "false", indicating that it is no longer the first appstart
e.putBoolean("key", false);
e.commit();
}
}
});

t.start();
}

关于android - 如何仅在第一个应用程序启动时打开 NavigationDrawer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18475419/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com