工具栏 - 添加了按钮 [英] Toolbar - add the up button

查看:196
本文介绍了工具栏 - 添加了按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的工具栏,而不是动作条,但我无法弄清楚如何添加向上按钮返回到previous活动。
我找不到,可能涉及到的任何方法。

I am trying to use the Toolbar instead of the ActionBar, but I can't figure out how to add the up button to return to the previous activity. I couldn't find any method that could relate to it.

如何添加向上按钮了吗?

How do I add the up button?

推荐答案

我猜你正在寻找的是这样的:

I guess what you are looking for is something like this:

Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar_detail);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

或者使用在片段的情况:

Or in case of using in Fragment:

Toolbar toolbar = (Toolbar) view.findViewById(R.id.app_bar_detail);
((ActionBarActivity) getActivity()).setSupportActionBar(toolbar);
((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

这将显示你的动作条工具栏里面,但不要担心,一切都会完全吻合。最后,你需要做的,如果你不想你的动作条下的任何阴影或它的任何背景是改变你的主题vaules / styles.xml。

This will show up your Action Bar inside of your toolbar, but don't worry everything will fit together well. The last you have to do if you dont want any shadow under your action bar or any background of it is change your theme in vaules/styles.xml.

<style name="AppThmeme.Base" parent="Theme.AppCompat.NoActionBar">

这篇关于工具栏 - 添加了按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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