Плавающая кнопка действия работает только на Android 5.0 или выше (API 21)

Я создал приложение, которое использует кнопку с плавающим действием (FAB). Моя проблема в том, что FAB не работает на API < 21. Когда я нажимаю на него, ничего не происходит. Это XML-файл FAB

<android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_AddGame"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="17dp"
            android:layout_marginRight="17dp"
            android:src="@drawable/ic_mode_edit_white_24dp"
            android:layout_gravity="bottom|right"
            android:background="@color/colorPrimary"
            />

Это манифест:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.mygamesapp.mygames">

<application
    android:allowBackup="true"
    android:configChanges="orientation"
    android:icon="@mipmap/mygames"
    android:label="@string/appName_home_name"
    android:screenOrientation="portrait"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".GameFocusActivity"
        android:configChanges="orientation"
        android:screenOrientation="portrait" />
    <activity android:name=".AddUserGame"/>
</application>

Есть два файла Gradle:

// Top-level build file where you can add configuration options common to      all sub-projects/modules.

 buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
   repositories {
      jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

А также

 plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "eu.mygamesapp.mygames"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),   'proguard-rules.pro'
    }
  }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1' //Needed for the Floating    Action Button
 }

Вот что должен сделать FAB:

  private void floatingActionButtonManagement() {
    FloatingActionButton fab_addGame = (FloatingActionButton)findViewById(R.id.fab_AddGame);
    fab_addGame.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            /*
            The currentConsole TextView is used to show at the user wich console is selected.
            We use it to have a strng that conteins the selected console.
            Call the method that manage the click event of the FloatingActionButton. We pass the console name.
             */
            String currentConsoleName = currentConsole.getText().toString();

            floatingActionButtonClickEvent(currentConsoleName);
        }
    });
}

private void floatingActionButtonClickEvent(String currentConsoleName) {
    /*
    Check if user have added a console. If he did start a menu for adding games, else start an
    error message
     */
    if (!currentConsoleName.equals(TXT_MAINACTVT_USER_HAVE_NOT_ADDED_CONSOLE)) {
        popUpViewAddGameBuild(currentConsoleName);
    }
    else
        mySimpleAlertDialogMethod("Attention!", "Before you enter game, you must enter a console.", true, true);
}



private void popUpViewAddGameBuild(String currentConsoleName) {
    /*
    Build the view that show the menu for adding games.
     */
    LayoutInflater inflater = this.getLayoutInflater();
    View popupView = inflater.inflate(R.layout.popupview_addgame, null);
    PopupWindow popupWindow = new PopupWindow(
            popupView,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);
    popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
    popupWindow.setFocusable(true);
    popupWindow.showAtLocation(popupView, 0, 0, 0);

    popUpAddGameSetFullAdapter(popupView, currentConsoleName);
    popUpAddGameClickEventManagment(popupView, popupWindow, currentConsoleName);
}

private void popUpAddGameSetFullAdapter(View popupView, String currentConsoleName) {
    /*
    Fill the listView whit all the games of the current console
     */
    ListView lstvw_addVideoGamePopUp_listOfAllGames = (ListView) popupView.findViewById(R.id.listView_all_games);

    Cursor cursor = appDataBase.getAllCurrentConsoleGames(currentConsoleName);
    String[] fromFieldNames = new String[]{AppDataBase.COL_VIDEOGAME_NAME};

    int[] toViewsIDs = new int[]{R.id.txt_popUpViewAddGame_lstvw_name};
    SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter(popupView.getContext(), R.layout.listview_allcurrentconsolegames, cursor, fromFieldNames, toViewsIDs, 0);
    lstvw_addVideoGamePopUp_listOfAllGames.setAdapter(myCursorAdapter);
}

Понятия не имею, в чем может быть проблема.. Что мне делать?

0 ответов

Другие вопросы по тегам