android ActionBar问题?

ActionBar无法显示ICON图标

https://img1.mukewang.com/5b42fe830001af0d05060789.jpg

请输入代码

<?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>

湖上湖
浏览 409回答 2
2回答

三国纷争

你应该用的是AppCompatActivity吧,V7库好像不能够在XML文件中直接配置android:icon,而且默认是不显示的,所以需要在代码中配置ActionBar actionBar = getSupportActionBar();&nbsp;&nbsp;&nbsp;&nbsp;actionBar.setIcon(R.mipmap.ic_launcher);&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;actionBar.setDisplayShowHomeEnabled(true);

幕布斯6054654

跟随时代的潮流,用Toolbar吧,actionBar真是太不好用了布局&nbsp;<android.support.v7.widget.Toolbar&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/toolbar"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="?attr/actionBarSize"&nbsp; &nbsp; &nbsp; &nbsp; app:layout_collapseMode="pin"&nbsp; &nbsp; &nbsp; &nbsp; app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />代码&nbsp;// App Logo&nbsp; &nbsp; &nbsp; &nbsp; mToolbar.setLogo(R.mipmap.ic_launcher);&nbsp; &nbsp; &nbsp; &nbsp; // Title&nbsp; &nbsp; &nbsp; &nbsp; mToolbar.setTitle("My Title");&nbsp; &nbsp; &nbsp; &nbsp; mToolbar.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);&nbsp; &nbsp; &nbsp; &nbsp; // Sub Title&nbsp; &nbsp; &nbsp; &nbsp; mToolbar.setSubtitle("Sub title");&nbsp; &nbsp; &nbsp; &nbsp; setSupportActionBar(mToolbar);&nbsp; &nbsp; &nbsp; &nbsp; // Navigation Icon 要設定在 setSupoortActionBar 才有作用,否則會出現 back button&nbsp; &nbsp; &nbsp; &nbsp; mToolbar.setNavigationIcon(R.mipmap.ic_back);&nbsp; &nbsp; &nbsp; &nbsp; //menu 点击事件&nbsp; &nbsp; &nbsp; &nbsp; mToolbar.setOnMenuItemClickListener(this);
打开App,查看更多内容
随时随地看视频慕课网APP