如何在操作栏上获取图标 [英] how to get an icon on action bar

查看:79
本文介绍了如何在操作栏上获取图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在操作栏上显示一个导航到页面的图标。

我已经为它下载了一个图标,将其复制到drawable文件夹中。



菜单中的代码.xml

< item 
android:id = @ + id / action_refresh
android:orderInCategory = 100
android:showAsAction = ifRoom
android:icon = @ drawable / back
android:title = 返回 /> />





onOptionItemSelected中的代码

  if (id == R.id.action_refresh){
Intent z = new Intent(getApplicationContext(),HomeScreen。 class );
startActivity(z);
返回 true;
}





运行应用程序i图标未显示。错误在哪里?

解决方案

检查出来: https://developer.android.com/training/basics/actionbar/adding-buttons.html [ ^ ]

并注意任何拼写错误和格式错误的xml标签。

i am trying to display an icon on action bar that will navigate to a page.
i have downloaded an icon for it, copied it in drawable folder.

code in menu .xml

<item
        android:id="@+id/action_refresh"
        android:orderInCategory="100"
        android:showAsAction="ifRoom"
        android:icon="@drawable/back"
        android:title="Back"/>/>



code in onOptionItemSelected

if (id == R.id.action_refresh) {
			Intent z=new Intent(getApplicationContext(),HomeScreen.class);
			startActivity(z);
			return true;
		}



on running the app i icon is not shown. where could the mistake be?

解决方案

Check this out: https://developer.android.com/training/basics/actionbar/adding-buttons.html[^]
and watch out for any typos and mal-formed xml tags.


这篇关于如何在操作栏上获取图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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