找不到符号方法isAttachedToWindow(View)

时间:2016-09-19 06:36:49

标签: android

protected void setupView(){
// TourGuide can only be setup after all the views is ready and obtain it's position/measurement
// so when this is the 1st time TourGuide is being added,
// else block will be executed, and ViewTreeObserver will make TourGuide setup process to be delayed until everything is ready
// when this is run the 2nd or more times, if block will be executed
if (ViewCompat.isAttachedToWindow(mHighlightedView)){
    startView();
} else {
    final ViewTreeObserver viewTreeObserver = mHighlightedView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                //noinspection deprecation
                mHighlightedView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                mHighlightedView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            startView();
        }
    });
}
}

收到错误

Error:(198, 23) error: cannot find symbol method isAttachedToWindow(View)

我在android studio中使用'com.android.support:appcompat-v7:22.0.1'

1 个答案:

答案 0 :(得分:0)

试试这个:

           if(Build.VERSION.SDK_INT == 18 ){
                // Do some stuff
            }
           else if (Build.VERSION.SDK_INT == 19) {
               // Do some stuff
            }
            else{
               // Do some stuff
             }