20

I am creating a Android Wear app that has an touch area. The user is suppose to be able to move it's finger in all directions over the screen (Think touchpad on your laptop). However the back swipe makes this a bit problematic. Any help with getting around this issue would be a great help.

How to disable the android wear back swipe?

/Jakob

ui-jakob
  • 417
  • 1
  • 4
  • 11

3 Answers3

36

There is an attribute in window style to disable this behavior:

<style name="AppTheme" parent="@android:style/Theme.DeviceDefault.Light">
    <item name="android:windowSwipeToDismiss">false</item>
</style>

Once you disable it you have to provide other way of exiting your app.
There is a DismissOverlayView class (listed here https://developer.android.com/training/wearables/apps/layouts.html#UiLibrary) that you should use instead.
Basically it provides an overlay that will show a red button with cross after a long press. Clicking the red button will exit your app.
enter image description here

Here is a video from Google I/O 2014 with some bookmarked moments:
https://www.youtube.com/watch?v=sha_w3_5c2c#t=1390 <- disabling android:windowSwipeToDismiss
https://www.youtube.com/watch?v=sha_w3_5c2c#t=1505 <- Java code for DismissOverlayView

You can also check another video called:
Fullscreen apps for Android Wear:
https://www.youtube.com/watch?v=naf_WbtFAlY

user1732313
  • 139
  • 1
  • 9
Maciej Ciemięga
  • 10,125
  • 1
  • 41
  • 48
  • Thanks will take a look! The DismissOverlay might not work for me since I might need the long press event also. But I will add some way to Dismiss. – ui-jakob Jul 16 '14 at 09:07
  • Please take a look at the java code on the video. They use a GestureDetector and onLongPress() callback to show the DismissOverlayView by calling mDismissOverlay.show() method. You can think of another gesture and implement it the same way:) I think it's not good to override two standard behaviors of exiting apps, so I hope your exit solution will be obvious to user and not hidden anywhere:) I can only advise to re-think the long press overriding once again if it's really necessary in your case:) Greetings! – Maciej Ciemięga Jul 16 '14 at 09:15
  • I think I might add a visible button for this reason. But have not decided yet. But I totally agree with you that it needs to be obvious. It is unfortunate that I might need both the default behaviors. – ui-jakob Jul 16 '14 at 09:37
  • Is there any option to avoid app go to background when user tap the screen? I want the app continue executing on screen even when user tap screen. I trying do it with this: https://developer.android.com/training/wearables/apps/always-on.html#EnableAmbient and this one: https://developer.android.com/training/wearables/ui/exit.html but nothing work for me. help please! :) – Cristian Nov 11 '16 at 14:02
9

You can try to write AndroidManifest.xml theme

android:theme="@style/Theme.Wearable.Modal inside activity tag

<activity
            android:name="com.smart.remote.wear.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.Wearable.Modal">
elifekiz
  • 1,456
  • 13
  • 26
0

If you want the whole app to override Swipe, place the theme property under your Manifest's <application> tag. If you want it to apply only to a certain activity, then place the property under that activity's <activity> tag.

So:

  1. create or update styles.xml in the res/values folder with the android:windowSwipeToDismiss property, such as:

    ... false

  2. If you want to override swipe in the whole app, Update your Manifest as such:

    <application
            ...
            android:theme="@style/AppTheme">
  1. If you want to override swipe in a specific activity, Update your Manifest as such:

        <activity
            ...
            android:theme="@style/AppTheme">
        </activity>
    

where ... represents all your other settings you already have. Remember you will need to give alternative ways out of the activity and/or app depending on which level you overrode

naimdjon
  • 3,162
  • 1
  • 20
  • 41
simba
  • 1