在Android的ActionBar中显示图标和标题 [英] Display icon and title in the ActionBar in Android
本文介绍了在Android的ActionBar中显示图标和标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在活动"的操作栏中同时显示图标和标题.这是我的应用的屏幕截图:
I want to display both icon and title in the action bar of an Activity. Here is the screenshot of my app now:
现在,我需要在操作栏中MyApp文本的左侧显示应用程序徽标.我已经尝试过以下代码来设置徽标,但是什么也没发生:
Now I need the app logo be displayed to the left of MyApp text in the action bar. I have already tried the following code to set the logo but nothing happened:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setLogo(R.drawable.ic_launcher_web);
getSupportActionBar().setDisplayUseLogoEnabled(true);
setContentView(R.layout.activity_main);
}
推荐答案
我刚刚尝试了您的代码,并且可行.
I just tried with your code, and this works.
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.mipmap.ic_launcher);
确保将父主题设置为Theme.AppCompat.Light.NoActionBar
.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
这篇关于在Android的ActionBar中显示图标和标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文