相关疑难解决方法(0)

如何禁用Android中的View上的任何事件?

我的问题很简单:如何禁用Android中的View上的任何事件?(包括删除它的可聚焦性,就像我只是希望它在视觉上存在但在其他一切上是不存在的)并且它是否在整个视图树上工作?(就像我在root上禁用事件一样,所有事件都将为其子节点禁用?).

现在,在你说什么之前我已经尝试了以下所有方法:

而这些方法似乎都不重要.

我已经直接尝试了它们WebView,以及所有内容的父布局,但我仍然可以与它进行交互.

任何的想法?

谢谢!

编辑#1

在视图顶部添加需要禁用的视图的解决方案不起作用.实际上,仍然可以点击内部视图,我尝试了一个简单的例子:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="#ff0000">
        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Click Me!"
        />
    </LinearLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#00000000"
    />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

在这里仍然可以点击button.

编辑#2

我想这样做的原因与我几周前提出的以下问题有关.

我所拥有的是一个ListView导航栏,它位于一个View包含我的应用内容的下方.这个实现的问题是,当我尝试滚动浏览ListView时,在它上面的图层中有一个可聚焦的视图,好的是ListView不滚动,而是它是焦点的顶视图(当有的时候就是这种情况) a WebviewEditText等等).

所以在其中一个答案中提到的是,我可以WebView通过覆盖禁用任何点击事件,setOnTouchListener但视图仍然集中在一起,我认为这就是为什么我的导航栏仍然存在同样的问题.

android android-layout android-view

6
推荐指数
1
解决办法
5227
查看次数

有没有办法以编程方式禁用特定布局中的所有项目?

我有一个游戏,我最近添加了一个全局高分功能,这让很多人感到不安,所以我想添加禁用它的选项.我做的是这样的:在我的设置活动视图中,我添加了以下内容:

<!-- High Score Tracking -->
 <LinearLayout android:layout_weight="40"
  android:layout_width="fill_parent" android:layout_height="wrap_content"
  android:orientation="vertical" android:padding="5dip">
  <LinearLayout android:layout_width="fill_parent"
   android:layout_height="wrap_content">
   <CheckBox android:text="@string/EnableHighscoreCBText"
    android:id="@+id/EnableHighscoreCB" android:layout_width="fill_parent"
    android:layout_height="wrap_content">
   </CheckBox>
  </LinearLayout>
  <!-- High score specific settings -->
  <LinearLayout android:layout_width="fill_parent"
   android:layout_height="wrap_content" android:orientation="horizontal"
   android:weightSum="100" android:padding="5dip">
   <CheckBox android:text="@string/EnableShareScoresCBText"
    android:id="@+id/EnableShareScoresCB" android:layout_width="fill_parent"
    android:layout_height="wrap_content">
   </CheckBox>

   <TextView android:id="@+id/DefaultPlayerNameTv"
    android:layout_width="wrap_content" android:layout_weight="30"
    android:layout_height="wrap_content" android:text="@string/pDefName"
    android:textSize="18sp">
   </TextView>
   <EditText android:id="@+id/PlayerNameEt"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="@string/pNameDefVal" android:layout_weight="70"
    android:textSize="18sp" android:maxLength="20">
   </EditText>
  </LinearLayout>
 </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我想要做的是当用户取消选中启用高分记跟踪复选框时,禁用整个"高分特定设置"布局.我尝试通过将其设置setEnabled为false来禁用它,但这根本不起作用.我应该使用视图组还是其他什么?我应该运行刷新方法来应用更改吗?

user-interface android

3
推荐指数
1
解决办法
8355
查看次数