android-在工具栏的子元素顶部添加backbutton

android-在工具栏的子元素顶部添加backbutton,第1张

概述我有以下布局文件.如何在下面的布局中的工具栏的Imageview子项的顶部(或像z索引一样覆盖)上添加后退按钮(箭头)?<LinearLayoutandroid:layout_height="wrap_content"android:layout_width="fill_parent"android:orientation="vertical"xmlns:android="http://schemas.android.

我有以下布局文件.如何在下面的布局中的工具栏的ImagevIEw子项的顶部(或像z索引一样覆盖)上添加后退按钮(箭头)?

<linearLayoutandroID:layout_height="wrap_content"androID:layout_wIDth="fill_parent"androID:orIEntation="vertical"xmlns:androID="http://schemas.androID.com/apk/res/androID"><Toolbar    androID:layout_wIDth="fill_parent"    androID:layout_height="600dp"    androID:ID="@+ID/toolbar"    androID:background="#313B45"    androID:weightSum="1"    androID:contentInsetleft="0dp"    androID:contentInsetStart="0dp"    xmlns:androID="http://schemas.androID.com/apk/res/androID">    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:orIEntation="vertical">        <ImageVIEw            androID:ID="@+ID/headerimage"            androID:layout_wIDth="fill_parent"            androID:layout_height="fill_parent"            androID:scaleType="fitXY"            androID:layout_gravity="left|top"            androID:layout_weight="1" />        <TextVIEw            androID:layout_wIDth="fill_parent"            androID:layout_height="fill_parent"            androID:text="New Text"            androID:ID="@+ID/textVIEw"            androID:scaleType="fitXY"            androID:layout_gravity="left|top"            androID:layout_weight="1" />    </linearLayout></Toolbar>

解决方法:

您必须通过以下行设置工具栏启用的主页按钮:getSupportActionbar().setdisplayHomeAsUpEnabled(true);并且要覆盖后退按钮上的 *** 作,您必须覆盖onoptionItemSelected方法.寻找给定的代码,它将帮助您…:D

        Toolbar toolbar = (Toolbar) findVIEwByID(R.ID.app_bar);        setSupportActionbar(toolbar);        getSupportActionbar().setHomebuttonEnabled(true);        getSupportActionbar().setdisplayHomeAsUpEnabled(true);

要覆盖OnoptionItemSelected,请使用以下代码

@OverrIDe    public boolean onoptionsItemSelected(MenuItem item) {    switch (item.getItemID()) {    case androID.R.ID.home:        finish();        break;    default:        break;    }        return super.onoptionsItemSelected(item);    }
总结

以上是内存溢出为你收集整理的android-在工具栏的子元素顶部添加backbutton全部内容,希望文章能够帮你解决android-在工具栏的子元素顶部添加backbutton所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1088955.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存