Floating Action Button

前端 未结 4 1608
猫巷女王i
猫巷女王i 2020-12-04 02:42

I have been trying to use Floating Action Button. I tried to use some of the resources suggested on here and the links were great; however, I couldn\'t use alot of them beca

4条回答
  •  执念已碎
    2020-12-04 03:12

    There is no need to create FloatingActionButton by yourself now. The new com.android.support:design:23.0.1 can do that for you. Just follow the below procedure.

    1.Add this line compile 'com.android.support:design:23.0.1' in dependencies in your build.gradle in Android Studio

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:design:23.0.1'
    }
    

    2.To create a FloatingActionButton using the following xml file.

    
    
            
    
            
    
    
    
    1. In MainActivity in onCreate method set setOnClickListener as follows

      FloatingActionButton fab; fab = (FloatingActionButton) getView().findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Do what you want here } });

提交回复
热议问题