2016-09-22 118 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