Java Code Examples for android.view.ViewGroup#findViewWithTag()

The following examples show how to use android.view.ViewGroup#findViewWithTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmileyView.java    From Ruisi with Apache License 2.0 6 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, final int page) {
    EmotionGridView v = container.findViewWithTag(page);
    if (v == null) {
        final int tabpos = pageToTabPos(page);
        int pageStart = page - getPageCountBefore(tabpos);
        int index = pageStart * ROW_COUNT * COLOUM_COUNT;

        v = new EmotionGridView(context, smileys.get(tabpos),
                COLOUM_COUNT, ROW_COUNT, index, emotionInputHandler);
        v.setLayoutParams(new LayoutParams(LMP, LMP));
        v.setTag(page);
        container.addView(v);
    }
    return v;
}
 
Example 2
Source File: BarUtils.java    From Android-UtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * 设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */

public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
        View fakeStatusBarView = decorView.findViewWithTag(FAKE_STATUS_BAR_VIEW_TAG);
        if (fakeStatusBarView != null) {
            if (fakeStatusBarView.getVisibility() == View.GONE) {
                fakeStatusBarView.setVisibility(View.VISIBLE);
            }
            fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        } else {
            decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
        }
        setRootView(activity);
    }
}
 
Example 3
Source File: AppUtils.java    From AndroidNavigation with MIT License 6 votes vote down vote up
public static int getStatusBarColor(final Window window) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return window.getStatusBarColor();
    } else {
        ViewGroup decorViewGroup = (ViewGroup) window.getDecorView();
        View statusBarView = decorViewGroup.findViewWithTag("custom_status_bar_tag");
        if (statusBarView != null) {
            Drawable drawable = statusBarView.getBackground();
            if (drawable instanceof ColorDrawable) {
                ColorDrawable colorDrawable = (ColorDrawable) drawable;
                return colorDrawable.getColor();
            }
        }
    }
    return Color.BLACK;
}
 
Example 4
Source File: StatusBarUtils.java    From MvpRoute with Apache License 2.0 6 votes vote down vote up
/**
 * 设置状态栏颜色
 *
 * @param activity activity
 * @param color    状态栏颜色值
 */
public static void setStatusBarColor(@NonNull final Activity activity,
									 @ColorInt final int color) {
	Window window = activity.getWindow();
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
		window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
		window.setStatusBarColor(color);
	} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
		ViewGroup decorView = (ViewGroup) window.getDecorView();
		View fakeStatusBarView = decorView.findViewWithTag(FAKE_STATUS_BAR_VIEW_TAG);
		if (fakeStatusBarView != null) {
			if (fakeStatusBarView.getVisibility() == View.GONE) {
				fakeStatusBarView.setVisibility(View.VISIBLE);
			}
			fakeStatusBarView.setBackgroundColor(color);
		} else {
			decorView.addView(createColorStatusBarView(activity, color));
		}
		fitWindowAndClipPadding(activity);
	}
}
 
Example 5
Source File: StatusBarKitkatImpl.java    From status-bar-compat with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void setStatusBarColor(Window window, int color) {
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

    ViewGroup decorViewGroup = (ViewGroup) window.getDecorView();
    View statusBarView = decorViewGroup.findViewWithTag(STATUS_BAR_VIEW_TAG);
    if (statusBarView == null) {
        statusBarView = new StatusBarView(window.getContext());
        statusBarView.setTag(STATUS_BAR_VIEW_TAG);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.TOP;
        statusBarView.setLayoutParams(params);
        decorViewGroup.addView(statusBarView);
    }
    statusBarView.setBackgroundColor(color);
    StatusBarCompat.internalSetFitsSystemWindows(window, true);
}
 
Example 6
Source File: StatusBarImmersiveUtils.java    From QPM with Apache License 2.0 6 votes vote down vote up
/**
 * 状态栏沉浸模式下(状态栏文字深颜色)
 * 设置沉浸式状态栏颜色
 *
 * @param colorStatusbar       状态栏颜色
 * @param defaultDarkIconColor 如果状态栏图标无法设置为深色图标 设置默认的状态栏颜色
 */
public static void setDarkIconStatusBarColor(Activity activity, int colorStatusbar, int defaultDarkIconColor) {
    ViewGroup contentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);
    View mStatusBarView = contentView.findViewWithTag(TAG_FAKE_STATUS_BAR_VIEW);
    if (mStatusBarView == null) {
        open(activity);
    }
    mStatusBarView = contentView.findViewWithTag(TAG_FAKE_STATUS_BAR_VIEW);
    if (mStatusBarView != null) {
        if (!StatusBarColorUtils.setStatusBarDarkIcon(activity, true)) {
            mStatusBarView.setBackgroundColor(defaultDarkIconColor);
        } else {
            mStatusBarView.setBackgroundColor(colorStatusbar);
            StatusBarColorUtils.setStatusBarDarkIcon(activity, true);
        }
    }
}
 
Example 7
Source File: BarUtils.java    From Android-utils with Apache License 2.0 6 votes vote down vote up
private static View applyStatusBarColor(final Window window,
                                        final int color,
                                        boolean isDecor) {
    ViewGroup parent = isDecor ?
            (ViewGroup) window.getDecorView() :
            (ViewGroup) window.findViewById(android.R.id.content);
    View fakeStatusBarView = parent.findViewWithTag(TAG_STATUS_BAR);
    if (fakeStatusBarView != null) {
        if (fakeStatusBarView.getVisibility() == View.GONE) {
            fakeStatusBarView.setVisibility(View.VISIBLE);
        }
        fakeStatusBarView.setBackgroundColor(color);
    } else {
        fakeStatusBarView = createStatusBarView(window.getContext(), color);
        parent.addView(fakeStatusBarView);
    }
    return fakeStatusBarView;
}
 
Example 8
Source File: LazyViewPagerAdapter.java    From likequanmintv with Apache License 2.0 5 votes vote down vote up
@Override
public View addLazyItem(ViewGroup container, int position) {
    View itemView = container.findViewWithTag(makeTag(position));
    if (itemView == null) {
        itemView = mLazyItems.get(position);
        itemView.setTag(makeTag(position));
        container.addView(itemView);
        mLazyItems.remove(position);
    }
    return itemView;
}
 
Example 9
Source File: BarUtils.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * 隐藏伪状态栏 View
 *
 * @param activity 调用的 Activity
 */
public static void hideFakeStatusBarView(Activity activity) {
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    View fakeStatusBarView = decorView.findViewWithTag(FAKE_STATUS_BAR_VIEW_TAG);
    if (fakeStatusBarView != null) {
        fakeStatusBarView.setVisibility(View.GONE);
    }
    View fakeTranslucentView = decorView.findViewWithTag(FAKE_TRANSLUCENT_VIEW_TAG);
    if (fakeTranslucentView != null) {
        fakeTranslucentView.setVisibility(View.GONE);
    }
}
 
Example 10
Source File: ToastEUtil.java    From Android with MIT License 5 votes vote down vote up
private ToastEUtil(Context context) {
    mContext = context;
    container = (ViewGroup) ((Activity) context).findViewById(android.R.id.content);
    View viewWithTag = container.findViewWithTag(TOAST_TAG);
    if(viewWithTag == null){
        v = ((Activity) context).getLayoutInflater().inflate(R.layout.item_toast, container);
        v.setTag(TOAST_TAG);
    }else{
        v = viewWithTag;
    }
    mContainer = (LinearLayout) v.findViewById(R.id.mbContainer);
    mContainer.setVisibility(View.GONE);
    mTextView = (TextView) v.findViewById(R.id.tips_tv);
    statusImg = (ImageView) v.findViewById(R.id.status_img);
}
 
Example 11
Source File: StatusBarColorUtils.java    From QPM with Apache License 2.0 5 votes vote down vote up
private static void removeFakeStatusBarViewIfExist(Activity activity) {
    Window window = activity.getWindow();
    ViewGroup mDecorView = (ViewGroup) window.getDecorView();

    View fakeView = mDecorView.findViewWithTag(TAG_FAKE_STATUS_BAR_VIEW);
    if (fakeView != null) {
        mDecorView.removeView(fakeView);
    }
}
 
Example 12
Source File: BarUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 隐藏 StatusBar View
 * @param window {@link Window}
 */
private static void hideStatusBarView(final Window window) {
    ViewGroup decorView = (ViewGroup) window.getDecorView();
    View fakeStatusBarView = decorView.findViewWithTag(TAG_STATUS_BAR);
    if (fakeStatusBarView == null) return;
    fakeStatusBarView.setVisibility(View.GONE);
}
 
Example 13
Source File: SwipeToAction.java    From OneTapVideoDownload with GNU General Public License v3.0 5 votes vote down vote up
public ViewHolder(View v) {
    super(v);

    ViewGroup vg = (ViewGroup) v;
    front = vg.findViewWithTag("front");
    revealLeft = vg.findViewWithTag("reveal-left");
    revealRight = vg.findViewWithTag("reveal-right");

    int childCount = vg.getChildCount();
    if (front == null) {
        if (childCount < 1) {
            throw new RuntimeException("You must provide a view with tag='front'");
        } else {
            front = vg.getChildAt(childCount-1);
        }
    }

    if (revealLeft == null || revealRight == null) {
        if (childCount < 2) {
            throw new RuntimeException("You must provide at least one reveal view.");
        } else {
            // set next to last as revealLeft view only if no revealRight was found
            if (revealLeft == null && revealRight == null) {
                revealLeft = vg.getChildAt(childCount - 2);
            }

            // if there are enough children assume the revealRight
            int i = childCount - 3;
            if (revealRight == null && i > -1) {
                revealRight = vg.getChildAt(i);
            }
        }
    }


}
 
Example 14
Source File: Helper.java    From backstack with Apache License 2.0 5 votes vote down vote up
/**
 * Re-enables a view. This will remove the view added
 * @param viewGroup
 */
public static void enable(ViewGroup viewGroup){
    View view = viewGroup.findViewWithTag(DISABLE);
    if (view != null){
        viewGroup.removeView(view);
    }

}
 
Example 15
Source File: BarUtils.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色
 *
 * @param activity       需要设置的activity
 * @param drawerLayout   DrawerLayout
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color,
                                           @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // 生成一个状态栏大小的矩形
    // 添加 statusBarView 到布局中
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    View fakeStatusBarView = contentLayout.findViewWithTag(FAKE_STATUS_BAR_VIEW_TAG);
    if (fakeStatusBarView != null) {
        if (fakeStatusBarView.getVisibility() == View.GONE) {
            fakeStatusBarView.setVisibility(View.VISIBLE);
        }
        fakeStatusBarView.setBackgroundColor(color);
    } else {
        contentLayout.addView(createStatusBarView(activity, color), 0);
    }
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1)
                .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(),
                        contentLayout.getPaddingRight(), contentLayout.getPaddingBottom());
    }
    // 设置属性
    setDrawerLayoutProperty(drawerLayout, contentLayout);
    addTranslucentView(activity, statusBarAlpha);
}
 
Example 16
Source File: Blurry.java    From MyBlogDemo with Apache License 2.0 4 votes vote down vote up
public static void delete(ViewGroup target) {
  View view = target.findViewWithTag(TAG);
  if (view != null) {
    target.removeView(view);
  }
}
 
Example 17
Source File: BarUtils.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
private static void hideStatusBarView(final Window window) {
    ViewGroup decorView = (ViewGroup) window.getDecorView();
    View fakeStatusBarView = decorView.findViewWithTag(TAG_STATUS_BAR);
    if (fakeStatusBarView == null) return;
    fakeStatusBarView.setVisibility(View.GONE);
}
 
Example 18
Source File: Blurry.java    From Blurry with Apache License 2.0 4 votes vote down vote up
public static void delete(ViewGroup target) {
  View view = target.findViewWithTag(TAG);
  if (view != null) {
    target.removeView(view);
  }
}
 
Example 19
Source File: Blurry.java    From likequanmintv with Apache License 2.0 4 votes vote down vote up
public static void delete(ViewGroup target) {
  View view = target.findViewWithTag(TAG);
  if (view != null) {
    target.removeView(view);
  }
}
 
Example 20
Source File: MultiStateListView.java    From Android-MultiStateListView with MIT License 4 votes vote down vote up
private ViewGroup findContainerView(ViewGroup parent) {
	return (ViewGroup) parent.findViewWithTag(TAG);
}