本文整理汇总了Java中android.view.ViewGroup.findViewWithTag方法的典型用法代码示例。如果您正苦于以下问题:Java ViewGroup.findViewWithTag方法的具体用法?Java ViewGroup.findViewWithTag怎么用?Java ViewGroup.findViewWithTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.ViewGroup
的用法示例。
在下文中一共展示了ViewGroup.findViewWithTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSelected
import android.view.ViewGroup; //导入方法依赖的package包/类
@Test
public void setSelected() throws Exception {
View pageView1 = mock(View.class, withSettings().extraInterfaces(PageView.class));
View pageView2 = mock(View.class, withSettings().extraInterfaces(PageView.class));
List<Page> pages = ImmutableList.of(
new Page("page1", R.drawable.ic_share, "page1", (context, overlayCallback) -> pageView1),
new Page("page2", R.drawable.ic_share, "page2", (context, overlayCallback) -> pageView2)
);
view.displayPages(pages, pages.get(0), false);
ViewGroup iconHolder = view.findViewById(R.id.tab_icons_holder);
Page selectedPage = pages.get(1);
view.setSelected(selectedPage);
for (int i = 0; i < iconHolder.getChildCount(); i++) {
View child = iconHolder.getChildAt(i);
assertTrue(child.isSelected() == ObjectUtil.equals(child.getTag(), selectedPage.getId()));
}
View selectedView = iconHolder.findViewWithTag(selectedPage.getId());
assertEquals(selectedPage.getId(), selectedView.getTag());
}
示例2: removeFakeStatusBarViewIfExist
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* use reserved order to remove is more quickly.
*/
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);
}
}
示例3: setColor
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* 设置状态栏颜色
*
* @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);
}
}
示例4: setColorDiff
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* 设置状态栏颜色(5.0以下无半透明效果,不建议使用)
*
* @param activity 需要设置的 activity
* @param color 状态栏颜色值
*/
@Deprecated
public static void setColorDiff(Activity activity, @ColorInt int color) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
transparentStatusBar(activity);
ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
// 移除半透明矩形,以免叠加
View fakeStatusBarView = contentView.findViewWithTag(FAKE_STATUS_BAR_VIEW_TAG);
if (fakeStatusBarView != null) {
if (fakeStatusBarView.getVisibility() == View.GONE) {
fakeStatusBarView.setVisibility(View.VISIBLE);
}
fakeStatusBarView.setBackgroundColor(color);
} else {
contentView.addView(createStatusBarView(activity, color));
}
setRootView(activity);
}
示例5: setColorForDrawerLayoutDiff
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
*
* @param activity 需要设置的activity
* @param drawerLayout DrawerLayout
* @param color 状态栏颜色值
*/
@Deprecated
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 生成一个状态栏大小的矩形
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(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
} else {
// 添加 statusBarView 到布局中
contentLayout.addView(createStatusBarView(activity, color), 0);
}
// 内容布局不是 LinearLayout 时,设置padding top
if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
}
// 设置属性
setDrawerLayoutProperty(drawerLayout, contentLayout);
}
}
示例6: addStatusBarAlpha
import android.view.ViewGroup; //导入方法依赖的package包/类
private static void addStatusBarAlpha(final Activity activity, final int alpha, boolean isDecor) {
ViewGroup parent = isDecor ?
(ViewGroup) activity.getWindow().getDecorView() :
(ViewGroup) activity.findViewById(android.R.id.content);
View fakeStatusBarView = parent.findViewWithTag(TAG_ALPHA);
if (fakeStatusBarView != null) {
if (fakeStatusBarView.getVisibility() == View.GONE) {
fakeStatusBarView.setVisibility(View.VISIBLE);
}
fakeStatusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
} else {
parent.addView(createAlphaStatusBarView(parent.getContext(), alpha));
}
}
示例7: enable
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* 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);
}
}
示例8: removeFakeStatusBarViewIfExist
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* use reserved order to remove is more quickly.
*/
private static void removeFakeStatusBarViewIfExist(Activity activity) {
Window window = activity.getWindow();
ViewGroup decorview = (ViewGroup) window.getDecorView();
View fakeView = decorview.findViewWithTag(TAG_FAKE_STATUS_BAR_VIEW);
if (fakeView != null) {
decorview.removeView(fakeView);
}
}
示例9: hideFakeStatusBarView
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* 隐藏伪状态栏 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);
}
}
示例10: clearPreviousSetting
import android.view.ViewGroup; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
private static void clearPreviousSetting(Activity activity) {
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
View fakeStatusBarView = decorView.findViewWithTag(FAKE_STATUS_BAR_VIEW_TAG);
if (fakeStatusBarView != null) {
decorView.removeView(fakeStatusBarView);
ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
rootView.setPadding(0, 0, 0, 0);
}
}
示例11: removeNoticeView
import android.view.ViewGroup; //导入方法依赖的package包/类
private static void removeNoticeView(final ViewGroup parent, int tag) {
View view = parent.findViewWithTag(tag + parent.hashCode());
if (view != null) {
parent.removeView(view);
view.setTag(null);
}
}
示例12: isVisible
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* Check is FancyShowCaseView visible
*
* @param activity should be used to find FancyShowCaseView inside it
*/
public static Boolean isVisible(@NonNull Activity activity) {
ViewGroup androidContent = (ViewGroup) activity.findViewById(android.R.id.content);
ViewGroup mRoot = (ViewGroup) androidContent.getParent().getParent();
FancyShowCaseView mContainer = (FancyShowCaseView) mRoot.findViewWithTag(CONTAINER_TAG);
return mContainer != null;
}
示例13: hideCurrent
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* Hide FancyShowCaseView
*
* @param activity should be used to hide FancyShowCaseView inside it
*/
public static void hideCurrent(@NonNull Activity activity) {
ViewGroup androidContent = (ViewGroup) activity.findViewById(android.R.id.content);
ViewGroup mRoot = (ViewGroup) androidContent.getParent().getParent();
FancyShowCaseView mContainer = (FancyShowCaseView) mRoot.findViewWithTag(CONTAINER_TAG);
mContainer.hide();
}
示例14: delete
import android.view.ViewGroup; //导入方法依赖的package包/类
public static void delete(ViewGroup target) {
View view = target.findViewWithTag(TAG);
if (view != null) {
target.removeView(view);
}
}
示例15: hideAlphaView
import android.view.ViewGroup; //导入方法依赖的package包/类
private static void hideAlphaView(final Activity activity) {
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
View fakeStatusBarView = decorView.findViewWithTag(TAG_ALPHA);
if (fakeStatusBarView == null) return;
fakeStatusBarView.setVisibility(View.GONE);
}