2015-06-27 21 views
16

Gần đây tôi đã chuẩn bị nhập thư viện AlexKolpa/fab-toolbar khi tôi nhận thấy các hình ảnh động không hoạt động, mặc dù tôi theo tất cả các hướng dẫn được đưa ra trong các liên kết dưới đây:Nút không hoạt động cho AlexKolpa/fab-toolbar

https://github.com/AlexKolpa/fab-toolbar

mã của tôi là như sau:

MainActivity

import android.animation.Animator; 
 
import android.animation.AnimatorInflater; 
 
import android.animation.ObjectAnimator; 
 
import android.support.v7.app.ActionBarActivity; 
 
import android.os.Bundle; 
 
import android.util.Log; 
 
import android.view.Menu; 
 
import android.view.MenuItem; 
 
import android.view.View; 
 
import android.view.animation.LinearInterpolator; 
 
import android.widget.Toast; 
 

 
import com.github.alexkolpa.fabtoolbar.FabToolbar; 
 

 

 
public class MainActivity extends ActionBarActivity implements View.OnClickListener{ 
 

 

 
    private FabToolbar fabToolbar; 
 

 
    @Override 
 
    protected void onCreate(Bundle savedInstanceState) { 
 
     super.onCreate(savedInstanceState); 
 
     setContentView(R.layout.activity_main); 
 

 
     fabToolbar = ((FabToolbar) findViewById(R.id.fab_toolbar)); 
 

 
     fabToolbar.setColor(getResources().getColor(R.color.blue)); 
 

 
//  findViewById(R.id.attach).setOnClickListener(this); 
 
     findViewById(R.id.attach).setOnClickListener(new View.OnClickListener(){ 
 
      public void onClick(View v){ 
 
       Log.e("SOMETHING","SOMETHING"); 
 
       fabToolbar.show(); 
 
      } 
 
     }); 
 

 
    } 
 

 
    @Override 
 
    public void onClick(View v){ 
 
     Toast.makeText(this,"This is a button click!", Toast.LENGTH_SHORT).show(); 
 
     fabToolbar.hide(); 
 
    } 
 

 
}

chính Hoạt động Giao diện:

<FrameLayout 
 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    xmlns:tb="http://schemas.android.com/apk/src/org.panel" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    tools:context=".MainActivity"> 
 

 
    <!-- <ImageView 
 
     android:id="@+id/policebox" 
 
     android:layout_width="200dp" 
 
     android:layout_height="200dp" 
 
     android:cropToPadding="true" 
 
     android:layout_centerInParent="true" 
 
     android:src="@drawable/dot" 
 
     android:text="@string/example1" 
 
     android:onClick="disappearBox" />--> 
 

 
    <com.github.alexkolpa.fabtoolbar.FabToolbar 
 
     android:id="@+id/fab_toolbar" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:layout_gravity="bottom" 
 
     tb:tb_animation_duration="500" 
 
     tb:tb_button_gravity="end" 
 
     tb:tb_container_gravity="center" 
 
     android:layout_alignParentBottom="true" 
 
     android:layout_alignParentLeft="true" 
 
     android:layout_alignParentStart="true"> 
 

 
     <ImageView 
 
      android:id="@+id/attach" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:src="@drawable/ic_whiteplus" 
 
      android:layout_marginLeft="@dimen/icon_margin" 
 
      android:layout_marginRight="@dimen/icon_margin" 
 
      /> 
 

 
     <!-- More buttons can be added here --> 
 

 
    </com.github.alexkolpa.fabtoolbar.FabToolbar> 
 

 
</FrameLayout>

Gradle nếu cần thiết:

repositories { 
 
    maven { 
 
     url "https://jitpack.io" 
 
    } 
 
} 
 

 
apply plugin: 'com.android.application' 
 

 
android { 
 
    compileSdkVersion 22 
 
    buildToolsVersion "21.1.2" 
 

 
    defaultConfig { 
 
     applicationId "com.example.gkvxm.animations" 
 
     minSdkVersion 15 
 
     targetSdkVersion 22 
 
     versionCode 1 
 
     versionName "1.0" 
 
    } 
 
    buildTypes { 
 
     release { 
 
      minifyEnabled false 
 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
 
     } 
 
    } 
 
} 
 

 
dependencies { 
 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
 
    compile 'com.android.support:appcompat-v7:22.1.1' 
 
    compile 'com.github.alexkolpa:floating-action-button-toolbar:0.5.1' 
 
    compile 'com.github.ozodrukh:CircularReveal:[email protected]' 
 
    compile 'com.melnykov:floatingactionbutton:1.3.0' 
 
}

Bất kỳ ý tưởng về làm thế nào tôi có thể giải quyết vấn đề này?

+0

Đã thử trên thiết bị trước kẹo hoặc kẹo? –

+0

Bạn đã cố bật tính năng có thể nhấp trong ImageView chưa? android: clickable = "true" – lal

+0

@ProkashSarkar Tôi đã thử trên một thiết bị lollipop, có vấn đề gì với thiết bị lollipop không? Và tôi đã không thử clickable, tôi sẽ cố gắng tiếp theo – LoneProgrammingWolf

Trả lời

0

Tôi đã sử dụng thư viện này và nó hoạt động hoàn hảo. Tôi cũng đã thử với mã của bạn trên Moto X 5.1 và Genymotion 4.4, trên cả hai hình động đang hoạt động.

Một số soi mói mặc dù:

  • Trong cách bố trí, như bạn đang sử dụng FrameLayout bạn không cần các thuộc tính:

    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    
  • Có một hình ảnh trong cách bố trí của bạn và bấm vào đó hình ảnh bạn lại thực hiện một nút show. Tôi không nghĩ rằng đó sẽ là một hành vi dự định. Ngay cả khi bạn loại bỏ phần đó, tiết lộ sẽ hoạt động tốt. Phần này:

    findViewById(R.id.attach).setOnClickListener(new View.OnClickListener() { 
        public void onClick(View v) { 
         Log.e("SOMETHING", "SOMETHING"); 
         fabToolbar.show(); 
        } 
    }); 
    
0

tôi chỉ đã tải về mã này ...

tôi tìm thấy bạn không biết làm thế nào để tìm id ...

vì vậy chỉ cần làm theo điều này, nó sẽ hoạt động

ImageView imageView; 
    imageView= (ImageView) findViewById(R.id.event); 
    imageView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Toast.makeText(SampleActivity.this, "Clicked", Toast.LENGTH_SHORT).show(); 
     } 
    }); 
Các vấn đề liên quan