2016-09-22 116 views
0

我想在动作条的ImageButton在我的应用程序是这样的:的ImageButton在操作栏的Android

enter image description here

我的XML代码:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <android.support.v7.widget.RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context="in.yumigo.yumigovendor.ui.activity.InvoiceActivity" 
     android:id="@+id/invoice_recycler_view"> 
    </android.support.v7.widget.RecyclerView> 

    <ImageButton 
     android:elevation="2200dp" 
     android:id="@+id/float_calendar" 
     android:background="@android:color/transparent" 
     style="@style/CalendarFloating" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/calendar_144" 
     android:layout_alignParentRight="true" /> 
</RelativeLayout> 

显然,按钮的动作条下隐藏像这样: enter image description here

如何实现它?

+0

前是U使用工具栏或旧的动作条? – darwin

+0

您需要自定义您自己的操作栏 –

+0

我没有在此处看到任何工具栏代码。请提供完整的代码 –

回答

0

改变你的亲戚布局的FrameLayout或协调布局然后给margintop到您的图像按钮,这将这样的伎俩

低于

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.tcyonline.android.myapplication.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <ImageButton 
     android:id="@+id/ntn" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="right" 
     android:layout_marginRight="15dp" 
     android:layout_marginTop="25dp" 
     android:background="@android:color/transparent" 
     android:elevation="10dp" 
     android:src="@drawable/calendar" /> 


    <include layout="@layout/content_main" /> 
</FrameLayout> 

enter image description here

看看布局
+0

已经给出了余量顶部,不适用于FrameLayout或CoordinatorLayout – androider

0

如果你可以把你的权利放在ActionBar以下,那么试着给你的imageButton一个负值marginTop

例如android:marginTop="-16dp"

您可能还需要使用elevation和/或bringToFront带给你的ImageButton在ActionBar