當前位置: 首頁>>代碼示例>>Java>>正文


Java View.isClickable方法代碼示例

本文整理匯總了Java中android.view.View.isClickable方法的典型用法代碼示例。如果您正苦於以下問題:Java View.isClickable方法的具體用法?Java View.isClickable怎麽用?Java View.isClickable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.View的用法示例。


在下文中一共展示了View.isClickable方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: withUsageHintOnClick

import android.view.View; //導入方法依賴的package包/類
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static Matcher<? super View> withUsageHintOnClick(final Matcher<? extends CharSequence> charSequenceMatcher) {
    return new TypeSafeMatcher<View>() {
        @Override
        protected boolean matchesSafely(View view) {
            if (!view.isClickable()) {
                return false;
            }
            AccessibilityNodeInfo.AccessibilityAction clickAction = findAction(view, AccessibilityNodeInfo.ACTION_CLICK);
            return charSequenceMatcher.matches(clickAction.getLabel());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("is clickable and has custom usage hint for ACTION_CLICK: ");
            charSequenceMatcher.describeTo(description);
        }
    };
}
 
開發者ID:novoda,項目名稱:espresso-support,代碼行數:20,代碼來源:AccessibilityViewMatchers.java

示例2: addOnClickListener

import android.view.View; //導入方法依賴的package包/類
/**
 * add childView id
 *
 * @param viewId add the child view id   can support childview click
 * @return if you use adapter bind listener
 * @link {(adapter.setOnItemChildClickListener(listener))}
 * <p>
 * or if you can use  recyclerView.addOnItemTouch(listerer)  wo also support this menthod
 */
@SuppressWarnings("unchecked")
public BaseViewHolder addOnClickListener(@IdRes final int viewId) {
    childClickViewIds.add(viewId);
    final View view = getView(viewId);
    if (view != null) {
        if (!view.isClickable()) {
            view.setClickable(true);
        }
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (adapter.getOnItemChildClickListener() != null) {
                    adapter.getOnItemChildClickListener().onItemChildClick(adapter, v, getClickPosition());
                }
            }
        });
    }

    return this;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:30,代碼來源:BaseViewHolder.java

示例3: addOnClickListener

import android.view.View; //導入方法依賴的package包/類
/**
 * add childView id
 *
 * @param viewId add the child view id   can support childview click
 * @return if you use adapter bind listener
 * @link {(adapter.setOnItemChildClickListener(listener))}
 * <p>
 * or if you can use  recyclerView.addOnItemTouch(listerer)  wo also support this menthod
 */

public BaseViewHolder addOnClickListener(final int viewId) {
    childClickViewIds.add(viewId);
    final View view = getView(viewId);
    if (!view.isClickable()) {
        view.setClickable(true);
    }
    if (view != null) {
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (adapter.getOnItemChildClickListener() != null) {
                    adapter.getOnItemChildClickListener().onItemChildClick(adapter, v, getClickPosition());
                }
            }
        });
    }

    return this;
}
 
開發者ID:liu-xiao-dong,項目名稱:JD-Test,代碼行數:30,代碼來源:BaseViewHolder.java

示例4: findClickableViewInChild

import android.view.View; //導入方法依賴的package包/類
private boolean findClickableViewInChild(View view, int x, int y) {
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            final Rect rect = new Rect();
            child.getHitRect(rect);

            final boolean contains = rect.contains(x, y);
            if (contains) {
                return findClickableViewInChild(child, x - rect.left, y - rect.top);
            }
        }
    } else if (view != childView) {
        return (view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode()));
    }

    return view.isFocusableInTouchMode();
}
 
開發者ID:yangchong211,項目名稱:YCUtils,代碼行數:20,代碼來源:MaterialRippleLayout.java

示例5: findClickableViewInChild

import android.view.View; //導入方法依賴的package包/類
private boolean findClickableViewInChild(View view, int x, int y) {
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            Rect rect = new Rect();
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
                return findClickableViewInChild(child, x - rect.left, y - rect.top);
            }
        }
    } else if (view != this.childView) {
        return view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode());
    }
    return view.isFocusableInTouchMode();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:MaterialRippleLayout.java

示例6: setOnItemClickListener

import android.view.View; //導入方法依賴的package包/類
/**
 * 為任意ViewGroup設置OnItemClickListener.
 * 該方法必須在addViews()方法之後調用,否則無效。
 * 因為ItemView 必須被添加在ViewGroup裏才能遍曆到。
 * 建議直接在addViews()方法裏傳入OnItemClickListener進行設置,性能更高
 *
 * @param viewGroup
 * @param onItemClickListener
 */
public static void setOnItemClickListener(final ViewGroup viewGroup, final OnItemClickListener onItemClickListener) {
    if (viewGroup == null || onItemClickListener == null) {
        return;
    }
    int childCount = viewGroup.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View itemView = viewGroup.getChildAt(i);
        //itemView之前沒有點擊事件才會去設置
        if (null != itemView && !itemView.isClickable()) {
            final int finalI = i;
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemClickListener.onItemClick(viewGroup, itemView, finalI);
                }
            });
        }
    }
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:29,代碼來源:ViewGroupUtils.java

示例7: onTouch

import android.view.View; //導入方法依賴的package包/類
@Override
public boolean onTouch(View v, MotionEvent event) {
    KeyboardUtils.hideSoftInput(mContext);
    View currentFocus = mContext.getCurrentFocus();
    //處理列表中的控件需要點擊兩次才生效的問題
    if (currentFocus != v && v.isClickable() && event.getAction() == MotionEvent.ACTION_DOWN) {
        v.requestFocus();
        return false;
    }
    
    if (currentFocus instanceof EditText) {
        mRootView.requestFocus();
    }
    return false;
}
 
開發者ID:SpannerBear,項目名稱:ValueAddSubView,代碼行數:16,代碼來源:FocusManager.java

示例8: RadiusViewDelegate

import android.view.View; //導入方法依賴的package包/類
public RadiusViewDelegate(View view, Context context, AttributeSet attrs) {
    this.view = view;
    this.mContext = context;
    obtainAttributes(context, attrs);
    view.setSelected(selected);
    if (!(view instanceof CompoundButton) && !view.isClickable()) {
        view.setClickable(isRippleEnable);
    }
}
 
開發者ID:AriesHoo,項目名稱:UIWidget,代碼行數:10,代碼來源:RadiusViewDelegate.java

示例9: avoidDoubleClicks

import android.view.View; //導入方法依賴的package包/類
/***
 * To prevent from double clicking the row item and so prevents overlapping fragment.
 * **/
public static void avoidDoubleClicks(final View view) {
    final long DELAY_IN_MS = 500;
    if (!view.isClickable()) {
        return;
    }
    view.setClickable(false);
    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            view.setClickable(true);
        }
    }, DELAY_IN_MS);
}
 
開發者ID:QuixomTech,項目名稱:DeviceInfo,代碼行數:17,代碼來源:Methods.java

示例10: onInterceptTouchEvent

import android.view.View; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent event) {
    int action = event.getActionMasked();
    boolean isScrollIdle = RecyclerListView.this.getScrollState() == RecyclerListView.SCROLL_STATE_IDLE;

    if ((action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) && currentChildView == null && isScrollIdle) {
        currentChildView = view.findChildViewUnder(event.getX(), event.getY());
        if (currentChildView instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) currentChildView;
            float x = event.getX() - currentChildView.getLeft();
            float y = event.getY() - currentChildView.getTop();
            final int count = viewGroup.getChildCount();
            for (int i = count - 1; i >= 0; i--) {
                final View child = viewGroup.getChildAt(i);
                if (x >= child.getLeft() && x <= child.getRight() && y >= child.getTop() && y <= child.getBottom()) {
                    if (child.isClickable()) {
                        currentChildView = null;
                        break;
                    }
                }
            }
        }
        currentChildPosition = -1;
        if (currentChildView != null) {
            currentChildPosition = view.getChildPosition(currentChildView);
            MotionEvent childEvent = MotionEvent.obtain(0, 0, event.getActionMasked(), event.getX() - currentChildView.getLeft(), event.getY() - currentChildView.getTop(), 0);
            if (currentChildView.onTouchEvent(childEvent)) {
                interceptedByChild = true;
            }
            childEvent.recycle();
        }
    }

    if (currentChildView != null && !interceptedByChild) {
        try {
            if (event != null) {
                mGestureDetector.onTouchEvent(event);
            }
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
    }

    if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) {
        if (!interceptedByChild && currentChildView != null) {
            selectChildRunnable = new Runnable() {
                @Override
                public void run() {
                    if (selectChildRunnable != null && currentChildView != null) {
                        currentChildView.setPressed(true);
                        selectChildRunnable = null;
                    }
                }
            };
            AndroidUtilities.runOnUIThread(selectChildRunnable, ViewConfiguration.getTapTimeout());
        }
    } else if (currentChildView != null && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_CANCEL || !isScrollIdle)) {
        if (selectChildRunnable != null) {
            AndroidUtilities.cancelRunOnUIThread(selectChildRunnable);
            selectChildRunnable = null;
        }
        currentChildView.setPressed(false);
        currentChildView = null;
        interceptedByChild = false;
    }
    return false;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:68,代碼來源:RecyclerListView.java


注:本文中的android.view.View.isClickable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。