android-studio - android ActionBar问题?

查看:133
本文介绍了android-studio - android ActionBar问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

ActionBar无法显示ICON图标

请输入代码

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.fiz.myapplication">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:icon="@mipmap/ic_launcher"
        android:label="demo"

        android:logo="@mipmap/ic_launcher">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

解决方案

跟随时代的潮流,用Toolbar吧,actionBar真是太不好用了

布局

 <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_collapseMode="pin"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


代码

 // App Logo
        mToolbar.setLogo(R.mipmap.ic_launcher);
        // Title
        mToolbar.setTitle("My Title");
        mToolbar.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
        // Sub Title
        mToolbar.setSubtitle("Sub title");

        setSupportActionBar(mToolbar);

        // Navigation Icon 要設定在 setSupoortActionBar 才有作用,否則會出現 back button
        mToolbar.setNavigationIcon(R.mipmap.ic_back);

        //menu 点击事件
        mToolbar.setOnMenuItemClickListener(this);

这篇关于android-studio - android ActionBar问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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