2

I'm brand new to coding and have been learning Kotlin for about a week now. But with everything shut down I have literally nothing else to do, so I'm going at it all day, every day. I built a basic app and have been trying to get basic haptic feedback on button pushes going. From my searches its not entirely clear what all the steps I have to take are.

So far I'm pasted this into the AndroidManifest

<uses-permission android:name="android.permission.VIBRATE"/>

And in the button XML I added

android:hapticFeedbackEnabled="true"

Surely I'm missing something I just don't know what. Below is all my manifest and all the XML for the first layout.

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

    <uses-permission android:name="android.permission.VIBRATE" />


    <application
        android:allowBackup="true"
        android:icon="@mipmap/happy"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/happy_round"
        android:screenOrientation="portrait"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="ExtraText">
        <activity android:name=".Answer1" />
        <activity android:name=".Answer2" />
        <activity android:name=".Answer3" />
        <activity android:name=".questions_page" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />
    </application>

</manifest>

And the XML layout. There are a few more layouts but I figured this would suffice to show what I've done so far. Any help would for a full on noob be very much appreciated.

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimaryDark"
    android:screenOrientation="portrait"
    tools:context=".MainActivity">

<Button
    android:id="@+id/pickAQuestionButton"
    android:layout_width="0dp"
    android:layout_height="99dp"
    android:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:background="@drawable/button_border"
    android:fontFamily="@font/chinesedragon"
    android:hapticFeedbackEnabled="true"
    android:text="Pick a Question..."
    android:textColor="#FFFFFF"
    android:textSize="30sp"
    app:layout_constraintBottom_toBottomOf="@+id/mainPic"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/mainPic"
    app:layout_constraintVertical_bias="0.97" />

<ImageView
    android:id="@+id/mainPic"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginTop="16dp"
    android:scaleType="fitXY"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/title"
    app:srcCompat="@drawable/confucious" />

<TextView
    android:id="@+id/title"
    android:layout_width="407dp"
    android:layout_height="72dp"
    android:layout_marginTop="40dp"
    android:fontFamily="@font/chinesedragon"
    android:gravity="center"
    android:lineSpacingExtra="14sp"
    android:text="Confucios Says..."
    android:textColor="#FFFFFF"
    android:textSize="50sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
  • you need to set onTouchListener and put view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING). "View" is the view you want to have haptic feedback – nvr Jul 01 '21 at 14:11
  • @nvr `FLAG_IGNORE_GLOBAL_SETTING` is deprecated in api version 33 – James Jun 24 '22 at 21:27

0 Answers0