2015-11-03 42 views
0

我更新了Android的支持庫,以修訂版23.1
然後我也沒能找到類無法實例FloatingActionButton

我的代碼

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 

    <TextView android:text="Hello World!" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

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

</RelativeLayout> 
+0

什麼是錯誤? – gvmani

+0

添加寬度和高度。 – natario

回答

1

請確保您有

compile 'com.android.support:design:23.1.0' 

in build.gradle

Android設計支持庫!= Android支持庫

+0

我正在使用Android Studio。任何特殊的圖書館android studio需要? –

+0

將上面的行添加到Android Studio中的'build.gradle'文件中。你知道'build.gradle'吧? –

+0

完成你所說的,但是當我使用FloatingActionButton它不給我預覽,也不能在手機上運行 –

0

在您的項目app/build.gradle中,將設計庫添加到您的依賴項中。這樣做之後不要忘記同步你的Gradle文件。

compile 'com.android.support:design:23.1.0'

這是副本,並從創建空白活動時由Android Studio生成佈局文件粘貼。你應該能夠使用它沒有問題。

<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_dialog_email" /> 

您將需要在您的dimens.xml中定義@dimen/fab_margin像這樣。

<dimen name = "fab_margin">16dp</dimen>

希望這將有助於。

0

首先你必須添加android支持設計庫。你可以從maven找到它或寫在build.gradle

compile 'com.android.support:design:23.1.0' 

其次添加像這樣的浮動按鈕高度寬度重力和圖標。

<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_dialog_email" 
/> 
+0

顯示此錯誤。以下類無法實例化: - android.support.design.widget.FloatingActionButton(打開類,顯示異常,清除緩存) –