Reputation: 194
I use https://github.com/makovkastar/FloatingActionButton
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
/>
<!-- The main content view -->
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.melnykov.fab.ObservableScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/obsScrollView">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#edeff2">
...
</LinearLayout>
</com.melnykov.fab.ObservableScrollView>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@drawable/ic_favorite_grey600_48dp"
fab:fab_colorNormal="@color/primary"
fab:fab_colorPressed="@color/primary_pressed"
fab:fab_colorRipple="@color/ripple"/>
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
Code:
...
// ScrollView
scrollView = (ObservableScrollView) findViewById(R.id.obsScrollView);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.attachToScrollView(scrollView);
fab.setColorNormal(getResources().getColor(R.color.primary));
fab.setColorPressed(getResources().getColor(R.color.primary_pressed));
...
But I have error when I go to this activity:
01-08 19:44:01.371 2311-2311/com.example.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.myapp, PID: 2311
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.VideoActivity}: android.view.InflateException: Binary XML file line #23: Error inflating class com.melnykov.fab.ObservableScrollView
...
Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class com.melnykov.fab.ObservableScrollView
Please, tell me, what I do wrong
app compiles without error
Dependencies:
When I set attr in XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@drawable/ic_favorite_grey600_48dp"
fab:fab_colorNormal="@color/primary"
fab:fab_colorPressed="@color/primary_pressed"
fab:fab_colorRipple="@color/ripple"/>
...
error:
Error:(137, -1) android-apt-compiler: [myapp] /Users/fedor/IdeaProjects/myapp/res/layout/video.xml:137: error: No resource identifier found for attribute 'fab_colorNormal' in package 'com.example.myapp'
Error:(137, -1) android-apt-compiler: [myapp] /Users/fedor/IdeaProjects/myapp/res/layout/video.xml:137: error: No resource identifier found for attribute 'fab_colorPressed' in package 'com.example.myapp'
Error:(137, -1) android-apt-compiler: [myapp] /Users/fedor/IdeaProjects/myapp/res/layout/video.xml:137: error: No resource identifier found for attribute 'fab_colorRipple' in package 'com.example.myapp'
but I imported the library
ObservableScrollView:
package com.melnykov.fab;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;
public class ObservableScrollView extends ScrollView {
public interface OnScrollChangedListener {
void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt);
}
private OnScrollChangedListener mOnScrollChangedListener;
public ObservableScrollView(Context context) {
super(context);
}
public ObservableScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mOnScrollChangedListener != null) {
mOnScrollChangedListener.onScrollChanged(this, l, t, oldl, oldt);
}
}
public void setOnScrollChangedListener(OnScrollChangedListener listener) {
mOnScrollChangedListener = listener;
}
}
Upvotes: 0
Views: 2974
Reputation: 91
In your XML file add xmlns:fab="http://schemas.android.com/tools"
. This will fix the "No resource identifier found for attribute..." errors.
Upvotes: 0