【问题标题】:how to disable Touch Screen in Android Phone?如何在 Android 手机中禁用触摸屏?
【发布时间】:2010-03-03 10:30:46
【问题描述】:

在显示进度条时,我想禁用触摸屏以限制安卓手机中的其他功能。

谁能指导我如何做到这一点?

任何帮助都会被应用。

【问题讨论】:

  • 这将剥夺用户的控制权和一个坏主意,所以我怀疑它可以完成,我不明白为什么有人会希望它完成
  • 好的,当我在列表上显示进度时,我已经在列表项上实现了点击功能。如果有人按下列表项,则在激活进度条期间。它控制了其他一些活动,所以我想限制它。
  • 只是从列表中删除 onClick 功能?
  • 我没有必要。还有其他建议吗?
  • 如果您尝试过我的解决方案并且效果很好,您能否将其标记为已接受的答案?

标签: android android-activity listactivity


【解决方案1】:

编辑

您可以通过实现 ListView 的自定义扩展来做到这一点,您将其设置为要在 XML 文件中使用的列表。然后在您的 CustomListView 中,实现 onTouchEvent 方法,如果您希望列表处理触摸,则仅调用 super.onTouchEvent。这就是我的意思:

在包含您的列表的布局文件中具有这种效果。

<com.steve.CustomListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/start_menu_background"
    android:cacheColorHint="#00000000"
    android:id="@android:id/list">
</com.steve.CustomListView>

然后有一个像这样的自定义类:

public class CustomListView extends ListView {
    Context mContext;

    public CustomListView (Context context, AttributeSet attrs){
        super(context, attrs);
        mContext = context;
    }

    public boolean onTouchEvent(MotionEvent event){
        if (event.getRawY() < 100){
            Log.d("Your tag", "Allowing the touch to go to the list.");
            super.onTouchEvent(event);
            return true;
        } else {
            Log.d("Your tag", "Not allowing the touch to go to the list.");
            return true;
        }
    }
}

此代码仅允许 ListView 处理位于屏幕前 100 个像素中的触摸事件。显然,将 if 语句替换为更适合您的应用程序的语句。一旦你让它工作,也不要留在日志语句中,因为你会在每个手势之后用数百条日志记录向自己发送垃圾邮件;他们只是为了说明正在发生的事情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多