android - 我的 Logo 未显示在操作栏中的正确位置

标签 android android-layout android-intent android-activity android-actionbar

我将此代码写入我的 Activity 并显示了我的 Logo ,但它在 Logo 前有一个空格

getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setIcon(R.drawable.emenu_logo);
    setTitle("");

截图:

enter image description here

我不知道怎么解决,请帮帮我!

最佳答案

制作布局并在您的自定义操作栏中膨胀...

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar mActionBar = getActionBar();
    mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(false);
    mActionBar.setDisplayHomeAsUpEnabled(false);
    mActionBar.setDisplayUseLogoEnabled(false);
    LayoutInflater mInflater = LayoutInflater.from(this);
    View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);   // inflate layout file

    /// TextView,ImageView,Button  etc element 

    mActionBar.setCustomView(mCustomView);
    mActionBar.setDisplayShowCustomEnabled(true);
    mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
   }
}

关于android - 我的 Logo 未显示在操作栏中的正确位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33799266/

相关文章:

android - "putExtra"是如何工作的?

android - Intent 未发送 ACTION_POWER_CONNECTED

android - fragment 和 activity 的核心区别是什么?哪些代码可以写成 fragment ?

android - 如何为两个元素之间有边距的 android 创建自定义 ListView ?

android - 在 ViewPager 中更改 fragment 时,使用 Elevation 创建的阴影会闪烁

android - 在使用 Android Studio 创建的 android 项目中,将自己的属性文件放在哪里?

android - RecyclerView Multiple View types (View Holders) 处理项目选择计数状态

android - 在 ViewPager 中获取 Activity 页面并更新内容

android - 在android中动态添加 View

android - 我无法应用自定义脚本插件