首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Android中同时在操作栏上设置图标和后退按钮

在Android中同时在操作栏上设置图标和后退按钮
EN

Stack Overflow用户
提问于 2020-02-15 11:17:54
回答 1查看 505关注 0票数 1

getSupportActionBar().setIcon(R.drawable.icon);不适用于安卓系统。

代码语言:javascript
运行
复制
    getSupportActionBar().setTitle("Dictionary");
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true); 
    getSupportActionBar().setIcon(R.drawable.ic_dictionary);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-15 11:23:02

在您的例子中,您应该在这些lines...if之前有一行代码--这就是问题所在。

代码语言:javascript
运行
复制
setSupportActionBar(toolbar);

然而,我自己使用材料工具栏和添加图标和文字的工具栏在xml中,并摆脱了这些方法!有关示例,请参阅我的xml文件之一

代码语言:javascript
运行
复制
<com.google.android.material.appbar.AppBarLayout
    android:background="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.google.android.material.appbar.MaterialToolbar
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/iv_back"
                android:onClick="onClick"
                android:layout_width="wrap_content"
                android:padding="16dp"
                android:background="@drawable/ripple_on_primary"
                android:layout_centerVertical="true"
                android:layout_alignParentEnd="true"
                android:src="@drawable/ic_back"
                android:layout_height="wrap_content"/>

            <TextView
                android:layout_centerVertical="true"
                android:layout_toStartOf="@id/iv_back"
                android:id="@+id/tv_toolbar"
                style="@style/tvTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/previous_transactions" />

            <TextView
                style="@style/tvContent"
                android:text="@string/help"
                android:id="@+id/tv_help"
                android:onClick="onClick"
                android:layout_centerVertical="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        </RelativeLayout>

    </com.google.android.material.appbar.MaterialToolbar>

</com.google.android.material.appbar.AppBarLayout>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60238220

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档