大家好,又见面了,我是全栈君。
非常多的Android应用左上角都有返回button
在默认的情况下 ADT会默认给一个返回图标
而作为开发需求 非常多都要求定制一个新的图标
在Android的站点上 发现了2种能够更改的方法
1.
在java代码环境中设置
actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.back);
假设有错误提示 Call requires API level 18 (current min is 14): android.app.ActionBar#setHomeAsUpIndicator
说明当前的最小API等级低于18 那么就參考另外一种方法了
2.
在styles.xml中新增一种style
<style name="style_titlebar_normal" parent="Theme.AppCompat.Light">
<item name="android:homeAsUpIndicator">@drawable/back</item> <!--返回icon-->
</style>
然后在AndroidManifest.xml中 在其Activity 的theme中设置成该style
<activity
android:name="com.logic.activity.Activity1"
android:theme="@style/style_titlebar_normal"
>
</activity>
这样的方法对API level没有要求 就是略复杂些
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116464.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有