How long is the event onLongPress in the Android?

Android supports an event onLongPress. The question I have is 'how long' (in milliseconds) is the 'press' to trigger the event?


The standard long press time is what is returned by getLongPressTimeout(), which is currently 500ms but may change (in 1.0 it was 1000ms but changed in a later release; maybe in the future it will be user-customizable).

The browser uses its own long press time because it has some more complicated interactions. I believe this should be 1000, though again it may change in the future. It is not adding the different timeouts together.


You can use the getLongPressTimeout method in android.view.ViewConfiguration to programmatically determine this value.

See the docs for details.


This is what R.array.long_press_timeout_selector_titles look like:

    <!-- Titles for the list of long press timeout options. -->
    <string-array name="long_press_timeout_selector_titles">
        <!-- A title for the option for short long-press timeout [CHAR LIMIT=25] -->
        <item>Short</item>
        <!-- A title for the option for medium long-press timeout [CHAR LIMIT=25] -->
        <item>Medium</item>
        <!-- A title for the option for long long-press timeout [CHAR LIMIT=25] -->
        <item>Long</item>
    </string-array>
    <!-- Values for the list of long press timeout options. -->
    <string-array name="long_press_timeout_selector_values" translatable="false">
        <item>400</item>
        <item>1000</item>
        <item>1500</item>
    </string-array>

Generally, like Roman Nurik mentioned, you can use ViewConfiguration.getLongPressTimeout() to programmatically obtain long press value value. The default value is 500ms.

/**
 * Defines the default duration in milliseconds before a press turns into
 * a long press
 */
private static final int DEFAULT_LONG_PRESS_TIMEOUT = 500;

But, the long press duration is customizable globally by setting it in accessibility. Values are Short (400 ms), Medium (1000 ms) or Long (1500 ms). You can see its source code in Settings:

// Long press timeout.
mSelectLongPressTimeoutPreference =
        (ListPreference) findPreference(SELECT_LONG_PRESS_TIMEOUT_PREFERENCE);
mSelectLongPressTimeoutPreference.setOnPreferenceChangeListener(this);
if (mLongPressTimeoutValueToTitleMap.size() == 0) {
    String[] timeoutValues = getResources().getStringArray(
            R.array.long_press_timeout_selector_values);
    mLongPressTimeoutDefault = Integer.parseInt(timeoutValues[0]);
    String[] timeoutTitles = getResources().getStringArray(
            R.array.long_press_timeout_selector_titles);
    final int timeoutValueCount = timeoutValues.length;
    for (int i = 0; i < timeoutValueCount; i++) {
        mLongPressTimeoutValueToTitleMap.put(timeoutValues[i], timeoutTitles[i]);
    }
}