2

我已經創建了一個頁面應用程序,其中浮動操作按鈕用於共享頁面中的內容。它完美地運行在android棒棒糖,但是當我在kitkat上運行該應用程序時,它不顯示。由於唯一的交互組件是FAB,因此用戶只能盯着看。我跑了一些搜索,發現FAB應該在kitkat上完美運行,並且只有在棒棒糖(如填充)時纔會出現一些問題。但是,它在棒棒糖中工作得很好。我是否必須將它更改爲棒棒糖之前版本的按鈕?我的第一個問題。任何幫助表示讚賞。謝謝。浮動操作按鈕不會出現在kitkat中

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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.ataraxianstudios.decksharer.MainActivity" 
    > 


    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/share1"/> 

<ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#016cb4"> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:id="@+id/llMain" 
     > 
<Spinner 
     android:id="@+id/osversions" 
     android:layout_width="220dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     /> 
    <ImageView 
     android:layout_width="60dp" 
     android:layout_height="80dp" 
     android:id="@+id/selectedImage" 
     /> 

</LinearLayout> 
    </ScrollView> 
</android.support.design.widget.CoordinatorLayout> 
+0

檢查[this](http://stackoverflow.com/a/31753179/4790490)out – Hearty

回答

0

您使用的設計支持庫activity_main.xml中? 這是一個例子:

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@android:drawable/ic_input_add" /> 

而在你的build.gradle:

依賴{ ..... 編譯 'com.android.support:design:xx.yy.zz' }

最後,在你的活動,你可以參考FAB這樣的:

FloatingActionButton btn = (FloatingActionButton) findViewById(R.id.fab); 

希望它可以幫助你! !

+0

我正是這樣做的。但是,當我在運行4.4的設備上測試它時,它不顯示。 –

+0

你可以顯示你在佈局中使用的代碼嗎? – FrancescoAzzola

+0

我編輯了OP來添加布局文件。 –

1

我也有同樣的問題可能是由於材料設計奇巧後引入的材料設計,這樣會有一些標籤或佈局的一些問題,但嘗試這個工作對我來說,也許對你有用..

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout  
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.ataraxianstudios.decksharer.MainActivity" 
> 



//Replace your fab from here 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#016cb4"> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:id="@+id/llMain" 
    > 
<Spinner 
    android:id="@+id/osversions" 
    android:layout_width="220dp" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    /> 
<ImageView 
    android:layout_width="60dp" 
    android:layout_height="80dp" 
    android:id="@+id/selectedImage" 
    /> 

</LinearLayout> 
</ScrollView> 


//to here: 
<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@drawable/share1"/> 
</android.support.design.widget.CoordinatorLayout> 
+0

應該標記爲回答,謝謝! –