Java Code Examples for android.app.Activity#findViewById()
The following examples show how to use
android.app.Activity#findViewById() .
These examples are extracted from open source projects.
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 Project: Overchan-Android File: GalleryFullscreen.java License: GNU General Public License v3.0 | 7 votes |
private GalleryFullscreenImpl(Activity activity) { window = activity.getWindow(); decorView = activity.getWindow().getDecorView(); decorView.setOnSystemUiVisibilityChangeListener(this); actionBar = activity.getActionBar(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { int color = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.materialPrimary, Color.WHITE); actionBar.setBackgroundDrawable(new ColorDrawable(color & Color.argb(192, 255, 255, 255))); } galleryNavbarView = (ViewGroup) activity.findViewById(R.id.gallery_navigation_bar_container); galleryNavbarView.setAlpha(0.75f); setTranslucentPanels(); showUI(true); fixNavbarOverlay(); }
Example 2
Source Project: tysq-android File: KeyboardUtils.java License: GNU General Public License v3.0 | 6 votes |
/** * Fix the bug of 5497 in Android. * <p>Don't set adjustResize</p> * * @param activity The activity. */ public static void fixAndroidBug5497(final Activity activity) { // Window window = activity.getWindow(); // int softInputMode = window.getAttributes().softInputMode; // window.setSoftInputMode(softInputMode & ~WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); final FrameLayout contentView = activity.findViewById(android.R.id.content); final View contentViewChild = contentView.getChildAt(0); final int paddingBottom = contentViewChild.getPaddingBottom(); sContentViewInvisibleHeightPre5497 = getContentViewInvisibleHeight(activity); contentView.getViewTreeObserver() .addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int height = getContentViewInvisibleHeight(activity); if (sContentViewInvisibleHeightPre5497 != height) { contentViewChild.setPadding( contentViewChild.getPaddingLeft(), contentViewChild.getPaddingTop(), contentViewChild.getPaddingRight(), paddingBottom + getDecorViewInvisibleHeight(activity) ); sContentViewInvisibleHeightPre5497 = height; } } }); }
Example 3
Source Project: shrinker File: ItemDetailFragment.java License: Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments().containsKey(ARG_ITEM_ID)) { // Load the dummy content specified by the fragment // arguments. In a real-world scenario, use a Loader // to load content from a content provider. mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID)); Activity activity = this.getActivity(); CollapsingToolbarLayout appBarLayout = (CollapsingToolbarLayout) activity.findViewById(R.id.toolbar_layout); if (appBarLayout != null) { appBarLayout.setTitle(mItem.content); } } }
Example 4
Source Project: MyBookshelf File: ImmersionBar.java License: GNU General Public License v3.0 | 5 votes |
/** * 解决顶部与布局重叠问题 * Sets fits system windows. * * @param activity the activity */ public static void setFitsSystemWindows(Activity activity) { ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content); for (int i = 0, count = parent.getChildCount(); i < count; i++) { View childView = parent.getChildAt(i); if (childView instanceof ViewGroup) { childView.setFitsSystemWindows(true); ((ViewGroup) childView).setClipToPadding(true); } } }
Example 5
Source Project: MVPArms File: ActivityLifecycleCallbacksImpl.java License: Apache License 2.0 | 5 votes |
@Override public void onActivityStarted(Activity activity) { Timber.i("%s - onActivityStarted", activity); if (!activity.getIntent().getBooleanExtra("isInitToolbar", false)) { //由于加强框架的兼容性,故将 setContentView 放到 onActivityCreated 之后,onActivityStarted 之前执行 //而 findViewById 必须在 Activity setContentView() 后才有效,所以将以下代码从之前的 onActivityCreated 中移动到 onActivityStarted 中执行 activity.getIntent().putExtra("isInitToolbar", true); //这里全局给Activity设置toolbar和title,你想象力有多丰富,这里就有多强大,以前放到BaseActivity的操作都可以放到这里 if (activity.findViewById(R.id.toolbar) != null) { if (activity instanceof AppCompatActivity) { ((AppCompatActivity) activity).setSupportActionBar(activity.findViewById(R.id.toolbar)); Objects.requireNonNull(((AppCompatActivity) activity).getSupportActionBar()).setDisplayShowTitleEnabled(false); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { activity.setActionBar(activity.findViewById(R.id.toolbar)); Objects.requireNonNull(activity.getActionBar()).setDisplayShowTitleEnabled(false); } } } if (activity.findViewById(R.id.toolbar_title) != null) { ((TextView) activity.findViewById(R.id.toolbar_title)).setText(activity.getTitle()); } if (activity.findViewById(R.id.toolbar_back) != null) { activity.findViewById(R.id.toolbar_back).setOnClickListener(v -> activity.onBackPressed()); } } }
Example 6
Source Project: mobile-manager-tool File: BottomActionBarFragment.java License: MIT License | 5 votes |
public void setUpQueueSwitch(Activity activity) { // TODO Auto-generated method stub albumArt = (RelativeLayout) activity.findViewById(R.id.audio_player_album_art_wrapper); listQueue = (RelativeLayout) activity.findViewById(R.id.audio_player_queue_wrapper); mQueue.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(albumArt.getVisibility()==View.VISIBLE){ listQueue.removeAllViews(); getFragmentManager().beginTransaction().add(R.id.audio_player_queue_wrapper, new NowPlayingFragment(), "NowPlayingTag").commit(); mQueue.setImageResource(R.drawable.music_btn_switch_queue_active); albumArt.setVisibility(View.GONE); listQueue.setVisibility(View.VISIBLE); // Fade out the pager container fade(albumArt, 0f); // Fade in the album art fade(listQueue, 1f); } else{ listQueue.setVisibility(View.GONE); albumArt.setVisibility(View.VISIBLE); mQueue.setImageResource(R.drawable.music_btn_switch_queue); // Fade out the pager container fade(listQueue, 0f); // Fade in the album art fade(albumArt, 1f); } } }); }
Example 7
Source Project: UTubeTV File: VideoPlayer.java License: The Unlicense | 5 votes |
public VideoPlayer(Activity activity, int fragmentContainerResID, VideoPlayerStateListener l) { super(); mListener = l; mContext = activity.getApplicationContext(); // install video fragment // will already exist if restoring Activity mVideoFragment = (VideoPlayerFragment) activity.getFragmentManager() .findFragmentById(fragmentContainerResID); // hide top bar when going fullscreen mTopBar = activity.findViewById(R.id.top_bar); mVideoFragment.setVideoFragmentListener(new VideoPlayerFragment.VideoFragmentListener() { @Override public void onFullScreen(boolean fullscreen) { mTopBar.setVisibility(fullscreen ? View.GONE : View.VISIBLE); } @Override public void playerInitialized() { if (AppUtils.instance(mContext).alwaysPlayFullscreen()) mVideoFragment.setFullscreen(true); // we avoid showing the view until after fullscreen is set after the player is setup mVideoBox.setVisibility(View.VISIBLE); } }); mVideoBox = activity.findViewById(R.id.video_player_box); setupToolbar(); }
Example 8
Source Project: Android-ScalingActivityAnimator File: ScalingActivityAnimator.java License: Eclipse Public License 1.0 | 5 votes |
/** * @param context * @param act * @param mainViewId main layout id * @param displayLayoutId displayLayoutId */ public ScalingActivityAnimator(Context context, Activity act, int mainViewId, int displayLayoutId){ this.mActivity = act; this.mMainView = act.findViewById(mainViewId); this.mPopupView = LayoutInflater.from(context).inflate(displayLayoutId, null); Point outSize = new Point(); mActivity.getWindowManager().getDefaultDisplay().getSize(outSize); screenHeight = outSize.y; popHeight = screenHeight/2; }
Example 9
Source Project: TLint File: StatusBarUtil.java License: Apache License 2.0 | 5 votes |
/** * 添加半透明矩形条 * * @param activity 需要设置的 activity * @param statusBarAlpha 透明值 */ private static void addTranslucentView(Activity activity, int statusBarAlpha) { ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); // 移除半透明矩形,以免叠加 if (contentView.getChildCount() > 1) { contentView.removeViewAt(1); } contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha)); }
Example 10
Source Project: tysq-android File: StatusBarUtils.java License: GNU General Public License v3.0 | 5 votes |
/** * 添加半透明矩形条 * * @param activity 需要设置的 activity * @param statusBarAlpha 透明值 */ private static void addTranslucentView(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) { ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); View fakeTranslucentView = contentView.findViewById(FAKE_TRANSLUCENT_VIEW_ID); if (fakeTranslucentView != null) { if (fakeTranslucentView.getVisibility() == View.GONE) { fakeTranslucentView.setVisibility(View.VISIBLE); } fakeTranslucentView.setBackgroundColor(Color.argb(statusBarAlpha, 0, 0, 0)); } else { contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha)); } }
Example 11
Source Project: MainActivityUIUtil File: MainUIUtil.java License: Apache License 2.0 | 5 votes |
private MainUIUtil(Activity activity){ this.activity = activity; activity. setContentView(R.layout.activity_main2); viewPager = (ViewPager) activity.findViewById(R.id.vp_container); bottomTabLayout = (PagerBottomTabLayout) activity.findViewById(R.id.tab); }
Example 12
Source Project: AwesomeValidation File: Validator.java License: MIT License | 5 votes |
public void set(Activity activity, int viewId, String regex, int errMsgId) { View view = activity.findViewById(viewId); String errMsg = activity.getResources().getString(errMsgId); if (view instanceof EditText) { set((EditText) view, regex, errMsg); } else if (view instanceof TextInputLayout) { set((TextInputLayout) view, regex, errMsg); } }
Example 13
Source Project: AndroidUiKit File: ImmersiveModeUtil.java License: Apache License 2.0 | 5 votes |
/** * 设置根布局参数 */ private static void setRootView(Activity activity) { ViewGroup parent = activity.findViewById(android.R.id.content); for (int i = 0, count = parent.getChildCount(); i < count; i++) { View childView = parent.getChildAt(i); if (childView instanceof ViewGroup) { childView.setFitsSystemWindows(true); ((ViewGroup) childView).setClipToPadding(true); } } }
Example 14
Source Project: adt-leanback-support File: ActionBarDrawerToggleHoneycomb.java License: Apache License 2.0 | 5 votes |
SetIndicatorInfo(Activity activity) { try { setHomeAsUpIndicator = ActionBar.class.getDeclaredMethod("setHomeAsUpIndicator", Drawable.class); setHomeActionContentDescription = ActionBar.class.getDeclaredMethod( "setHomeActionContentDescription", Integer.TYPE); // If we got the method we won't need the stuff below. return; } catch (NoSuchMethodException e) { // Oh well. We'll use the other mechanism below instead. } final View home = activity.findViewById(android.R.id.home); if (home == null) { // Action bar doesn't have a known configuration, an OEM messed with things. return; } final ViewGroup parent = (ViewGroup) home.getParent(); final int childCount = parent.getChildCount(); if (childCount != 2) { // No idea which one will be the right one, an OEM messed with things. return; } final View first = parent.getChildAt(0); final View second = parent.getChildAt(1); final View up = first.getId() == android.R.id.home ? second : first; if (up instanceof ImageView) { // Jackpot! (Probably...) upIndicatorView = (ImageView) up; } }
Example 15
Source Project: MaterialQQLite File: FullScreenKeyboradBug.java License: Apache License 2.0 | 5 votes |
private FullScreenKeyboradBug(Activity activity) { FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content); mChildOfContent = content.getChildAt(0); mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { possiblyResizeChildOfContent(); } }); frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams(); }
Example 16
Source Project: MediaPlayer-Extended File: Utils.java License: Apache License 2.0 | 4 votes |
public static void setActionBarSubtitleEllipsizeMiddle(Activity activity) { // http://blog.wu-man.com/2011/12/actionbar-api-provided-by-google-on.html int subtitleId = activity.getResources().getIdentifier("action_bar_subtitle", "id", "android"); TextView subtitleView = (TextView) activity.findViewById(subtitleId); subtitleView.setEllipsize(TextUtils.TruncateAt.MIDDLE); }
Example 17
Source Project: iBeebo File: AnimationUtility.java License: GNU General Public License v3.0 | 4 votes |
public static View getAppContentView(Activity activity) { final View appView = activity.findViewById(android.R.id.content); return appView; }
Example 18
Source Project: incubator-weex-playground File: WeexUiTestCaseTcDowngradeAppVTrue.java License: Apache License 2.0 | 4 votes |
public void testDowngrade(){ for(final View caseView : mCaseListIndexView){ if (((WXTextView)caseView).getText().toString().equals("TC_Downgrade")){ Log.e(TAG, "TC_Downgrade find"); final WXTextView inputView = (WXTextView)caseView; mInstrumentation.runOnMainSync(new Runnable() { @Override public void run() { inputView.requestFocus(); inputView.performClick(); } }); sleep(2000); setActivity(WXPageActivity.wxPageActivityInstance); Activity activity2 = getActivity(); ViewGroup myGroup = (ViewGroup)(activity2.findViewById(R.id.container)); ArrayList<View> inputListView = new ArrayList<View>(); inputListView = ViewUtil.findViewWithText(myGroup, "TC_Downgrade_appV_True"); // myGroup.findViewsWithText(inputListView, "TC_Downgrade_appV_True", View.FIND_VIEWS_WITH_TEXT); Log.e(TAG, "TC_Downgrade_appV_True== " + inputListView.size()); sleep(2000); if(inputListView.size()!=0){ final WXTextView inputTypeView = (WXTextView)inputListView.get(0); mInstrumentation.runOnMainSync(new Runnable() { @Override public void run() { inputTypeView.requestFocus(); inputTypeView.performClick(); Log.e(TAG, "TC_Downgrade_appV_True clcik!"); } }); sleep(2000); Log.e(TAG, "TC_Downgrade_appV_True snap!"); // screenShot("TC_Downgrade_appV_True"); ScreenShot.takeScreenShotIncludeDialog(getActivity(), "TC_Downgrade_appV_True"); sleep(2000); } } } }
Example 19
Source Project: WeexOne File: WeexUiTestCaseTcTextType.java License: MIT License | 4 votes |
public void testTextType(){ for(final View caseView : mCaseListIndexView){ if (((WXTextView)caseView).getText().toString().equals("TC_Text")){ Log.e(TAG, "TC_Text find"); final WXTextView inputView = (WXTextView)caseView; mInstrumentation.runOnMainSync(new Runnable() { @Override public void run() { inputView.requestFocus(); inputView.performClick(); } }); sleep(2000); setActivity(WXPageActivity.wxPageActivityInstance); Activity activity2 = getActivity(); Log.e(TAG, "activity2 = " + activity2.toString()); ViewGroup myGroup = (ViewGroup)(activity2.findViewById(R.id.container)); Log.e(TAG, myGroup.toString()); ArrayList<View> inputListView = new ArrayList<View>(); inputListView = ViewUtil.findViewWithText(myGroup, "TC_Text_Type"); // myGroup.findViewsWithText(inputListView, "TC_Text_Type", View.FIND_VIEWS_WITH_TEXT); Log.e(TAG, "TC_Text_Type size== " + inputListView.size()); if(inputListView.size()!=0){ final WXTextView inputTypeView = (WXTextView)inputListView.get(0); mInstrumentation.runOnMainSync(new Runnable() { @Override public void run() { inputTypeView.requestFocus(); inputTypeView.performClick(); Log.e(TAG, "TC_Text_Type clcik!"); // screenShot("TC_Input_Type"); } }); sleep(3000); Log.e(TAG, "TC_Text_Type snap!"); screenShot("TC_Text_Type"); } } } }
Example 20
Source Project: Aurora File: ArmsUtils.java License: Apache License 2.0 | 2 votes |
/** * findview * * @param activity * @param viewName * @param <T> * @return */ public static <T extends View> T findViewByName(Context context, Activity activity, String viewName) { int id = getResources(context).getIdentifier(viewName, "id", context.getPackageName()); T v = (T) activity.findViewById(id); return v; }