2016-02-03 147 views
0

我正在開發帶有浮動操作按鈕的Android應用程序。隱藏浮動操作按鈕

這個按鈕通常顯示在我的android版本(5)中,但在android 4.3 FAB是隱藏的,你可以點擊它,但即使它工作也不顯示。

這是我的代碼:

<View 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:focusable="true" 
    android:focusableInTouchMode="true"/> 

<LinearLayout 
    android:id="@+id/llTop" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="@dimen/textPaddings" 
    android:background="@color/headerColor" 
    android:orientation="horizontal" 
    android:weightSum="5"> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="3" 
     android:padding="@dimen/textPaddings" 
     android:text="Saldo disponibile:" 
     android:textColor="@color/white" 
     android:textSize="20sp" 
     android:textStyle="italic" /> 

    <TextView 
     android:id="@+id/tvBudget" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:gravity="end" 
     android:padding="@dimen/textPaddings" 
     android:text="" 
     android:textColor="@color/white" 
     android:textSize="20sp" 
     android:textStyle="bold" /> 

</LinearLayout> 

<ListView 
    android:id="@+id/lvTransactions" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/llBot" 
    android:layout_below="@+id/llTop" 
    android:layout_marginLeft="@dimen/textPaddings" 
    android:layout_marginRight="@dimen/textPaddings"> 

</ListView> 


<android.support.design.widget.FloatingActionButton 
    android:id="@+id/btnAdd" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentEnd="true" 
    android:layout_alignTop="@+id/llBot" 
    android:layout_marginTop="-15dp" 
    android:clickable="true" 
    android:src="@drawable/piu" 
    app:fabSize="mini" 
    app:layout_anchor="@id/llBot" /> 

<LinearLayout 
    android:id="@+id/llBot" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_margin="@dimen/textPaddings" 
    android:background="@color/headerColor" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="2"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/textPaddings" 
      android:layout_weight="1" 
      android:text="Descrizione:" 
      android:textColor="@color/whiteOpaque" 
      android:textSize="15sp" 
      android:textStyle="italic" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/textPaddings" 
      android:layout_weight="1" 
      android:text="Importo:" 
      android:textColor="@color/whiteOpaque" 
      android:textSize="15sp" 
      android:textStyle="italic" /> 
     <!--<Button--> 
      <!--android:layout_width="0dp"--> 
      <!--android:layout_height="50dp"--> 
      <!--android:layout_weight="1"--> 
      <!--android:text="+"--> 
      <!--android:textSize="25sp"--> 
      <!--android:onClick="add"--> 
      <!--/>--> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="2"> 

     <EditText 
      android:id="@+id/etDescr" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/textPaddings" 
      android:layout_weight="1" 
      android:background="@drawable/edittext_rounded" 
      android:hint="descrizione spesa" 
      android:inputType="textCapSentences" 
      android:paddingEnd="10dp" 
      android:paddingStart="10dp" /> 

     <EditText 
      android:id="@+id/etImporto" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/textPaddings" 
      android:layout_weight="1" 
      android:background="@drawable/edittext_rounded" 
      android:drawableEnd="@drawable/euro" 
      android:hint="importo" 
      android:inputType="numberDecimal" 
      android:paddingEnd="10dp" 
      android:paddingStart="10dp" /> 
    </LinearLayout> 

    <RadioGroup 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="2" 

     > 

     <RadioButton 
      android:id="@+id/rbEntrata" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Entrata" 
      android:textColor="@color/white" 
      android:textSize="15sp" /> 

     <RadioButton 
      android:id="@+id/rbUscita" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:checked="true" 
      android:text="Uscita" 
      android:textColor="@color/white" 
      android:textSize="15sp" /> 
    </RadioGroup> 
</LinearLayout> 

我想不通爲什麼它隱藏在一些設備和其他顯示..

+2

http://android-developers.blogspot.com/2015/05/android-design-support-library.html –

+1

好的,很好的答案。謝謝!所以我會改變老版本的代碼..再次感謝,如果你張貼它作爲答案,我會投票 –

+2

很高興聽到它的幫助。這就是我想要的。 :) –

回答

1

由於@Alex Chengalan建議,我張貼答覆希望別人可能需要它:)

this post他找到了解釋,因爲FAB已經添加了棒棒糖,以前的Android版本不能使用它。

所以你將有一個工作的FAB,但隱藏和根本沒有顯示。 (如果你點擊它,它會起作用,但你不會看到它)。