微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Android的ActionBar左侧放置两个按钮

如何解决在Android的ActionBar左侧放置两个按钮

我正在尝试构建一个ActionBar,在它的左侧有两个图标,其余的都在右侧。这两个项目将是一个徽标,单击该徽标可将用户重定向到主页,而单击后退按钮可将用户重定向到“向上翻页”。徽标应显示在最左侧,认的后退箭头应显示在其后。

当前,我已经实现了“向上翻页功能(使用认的后退箭头),该项目显示在左侧,但是我也没有成功将徽标放在此处。

这是我到目前为止所拥有的(简化了代码以专注于问题的实质):

layout_action_bar.xml:

Channels.list

menu_base.xml(不是必需的,只是为了提供有关我在ActionBar右侧的内容的上下文):

<!-- Custom layout for the action bar,so that we are able to center the text in it -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingRight="@dimen/action_bar_text_padding_right"
        android:id="@+id/txt_action_bar_title"
        android:singleLine="true"
        android:ellipsize="end"
        style="@style/Widget.ActionBar.Text"/>

</LinearLayout>

menu_base在CreateOptionsMenu()上膨胀,并且在ActionBar的那侧一切正常。

BaseActivityMenu.java:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      tools:context=".BaseActivity">

     <item
        android:id="@+id/action_menu"
        android:icon="@drawable/ic_menu"
        android:orderInCategory="1"
        android:title="@string/menu_drawer_open_accessibility"
        app:showAsAction="always"/>

     <item android:id="@+id/search"
          android:title="@string/actionbar_search_button_tooltip"
          android:icon="@drawable/ic_navigation_search"
          app:showAsAction="always|collapseActionView"
          app:actionViewClass="androidx.appcompat.widget.SearchView"
        />

</menu>

从视觉上看,这就是我目前所拥有的:My ActionBar

我该如何实现?

解决方法

在您的layout_action_bar.xml中,在LinearLayout中添加以下代码:

Map map=Map();
map ={"name":"abc","id":"1"};

Future<bool> createStudent(String schoolId) async {
 var newStudent = await db .collection('schoolStudents') .doc(schoolId)
 .collection('students')
 .add({
 'studentFirstName': _profile.studentFirstName,'studentSurname': _profile.studentSurname,'yearLevel': _profile.yearLevel,'preferredHand': _profile.preferredHand,'background': map,}

然后在您的活动中,添加以下代码行:

<ImageButton
    android:id="@+id/homeBtn"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:background="@android:color/transparent"
    android:src="@drawable/ic_home"/>

<ImageButton
    android:id="@+id/topBtn"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:background="@android:color/transparent"
    android:src="@drawable/ic_back_up"/>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。