博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Implementing Temporal Navigation 实现时间导航
阅读量:4046 次
发布时间:2019-05-24

本文共 2594 字,大约阅读时间需要 8 分钟。

Temporal navigation is navigation to previously visited screens. Users can visit previous screens by pressing the device Back button. This user interface pattern is described further in in Designing Effective Navigation and in .

Android handles basic Back navigation for you (see for details on this behavior).  http://blog.csdn.net/sergeycao

Implement Back Navigation with Fragments

When using fragments in your application, individual objects can represent context changes that should be added to the back stack. For example, if you are implementing a on a handset by swapping out fragments (thus emulating a call), you should ensure that pressing the Back button on a detail screen returns the user to the master screen. To do so, you can use :

// Works with either the framework FragmentManager or the// support package FragmentManager (getSupportFragmentManager).getFragmentManager().beginTransaction()        .add(detailFragment, "detail")        // Add this transaction to the back stack and commit.        .addToBackStack()        .commit();

The activity's handles Back button presses if there are objects on the back stack. When this happens, the pops the most recent transaction off the back stack and performs the reverse action (e.g., removing a fragment if the transaction added it).

If your application updates other user interface elements to reflect the current state of your fragments, such as the action bar, remember to update the UI when you commit the transaction. You should update your user interface after the fragment manager back stack changes in addition to when you commit the transaction. You can listen for when a FragmentTransaction is reverted by setting up an :

getFragmentManager().addOnBackStackChangedListener(        new FragmentManager.OnBackStackChangedListener() {            public void onBackStackChanged() {                // Update your UI here.            }        });

Implement Back Navigation with WebViews

If a part of your application is contained in a , it may be appropriate for Back to traverse browser history. To do so, you can override and proxy to the WebView if it has history state:

@Overridepublic void onBackPressed() {    if (mWebView.canGoBack()) {        mWebView.goBack();        return;    }    // Otherwise defer to system default behavior.    super.onBackPressed();}

Be careful when using this mechanism with highly dynamic web pages that can grow a large history. Pages that generate an extensive history, such as those that make frequent changes to the document hash, may make it tedious for users to get out of your activity.

你可能感兴趣的文章
No.147 - LeetCode1108
查看>>
No.174 - LeetCode1305 - 合并两个搜索树
查看>>
No.175 - LeetCode1306
查看>>
No.176 - LeetCode1309
查看>>
No.182 - LeetCode1325 - C指针的魅力
查看>>
mysql:sql alter database修改数据库字符集
查看>>
mysql:sql truncate (清除表数据)
查看>>
yuv to rgb 转换失败呀。天呀。谁来帮帮我呀。
查看>>
yuv420 format
查看>>
yuv420 还原为RGB图像
查看>>
LED恒流驱动芯片
查看>>
驱动TFT要SDRAM做为显示缓存
查看>>
使用file查看可执行文件的平台性,x86 or arm ?
查看>>
qt5 everywhere 编译summary
查看>>
qt5 everywhere编译完成后,找不到qmake
查看>>
qt 创建异形窗体
查看>>
可重入函数与不可重入函数
查看>>
简单Linux C线程池
查看>>
内存池
查看>>
输入设备节点自动生成
查看>>