Example usage for android.app Activity findViewById

List of usage examples for android.app Activity findViewById

Introduction

In this page you can find the example usage for android.app Activity findViewById.

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds a view that was identified by the android:id XML attribute that was processed in #onCreate .

Usage

From source file:org.mozilla.focus.utils.ViewUtils.java

/**
 * Update the alpha value of the view with the given id. All kinds of failures (null activity,
 * view not found, ..) will be ignored by this method.
 *//*w  w  w  .  ja v a 2 s . c  om*/
public static void updateAlphaIfViewExists(@Nullable Activity activity, @IdRes int id, float alpha) {
    if (activity == null) {
        return;
    }

    final View view = activity.findViewById(id);
    if (view == null) {
        return;
    }

    view.setAlpha(alpha);
}

From source file:Main.java

/**
 *
 * @param act/*  w  w w  . j ava 2 s .  c  om*/
 * @return
 */
public static RelativeLayout getContainerView(Activity act) {
    // create a new relative layout
    RelativeLayout rl = new RelativeLayout(act);

    // fint the root view of the activity
    ViewGroup fl = (ViewGroup) act.findViewById(android.R.id.content);
    fl = (ViewGroup) fl.getChildAt(0);
    Log.d("DEBUG", "w: " + fl.getWidth() + "h: " + fl.getHeight());

    // Params
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-1, -1);
    //        new FrameLayout.LayoutParams(-1, -1);
    // add to the root view of the activity
    fl.addView(rl, params);

    return rl;
}

From source file:com.edmondapps.utils.android.Utils.java

/**
 * Call {@link Activity#findViewById(int)} with the given parameters. The
 * return type of the {@code View} is inferred by the generic type V.
 * /*from  w ww . jav  a 2 s. co  m*/
 * @throws ClassCastException
 *             if the view is not of type V.
 * @deprecated Use {@link ViewUtils#findView(Activity, int)}
 */
// let it crash run-time!
@SuppressWarnings("unchecked")
@Deprecated
public static <V extends View> V findView(Activity activity, int id) {
    return (V) activity.findViewById(id);
}

From source file:org.tanrabad.survey.presenter.view.MainActivityNavigation.java

public static void setup(Activity activity) {
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.navigation);
    if (navigationView == null) {
        TanrabadApp.log(new IllegalArgumentException("NavigationView of MainActivity is Null"));
        return;/*  ww w  . ja v  a 2  s.  c  om*/
    }
    navigationView.setItemIconTintList(null);
    setupHeaderView(navigationView);
    navigationView.setNavigationItemSelectedListener(new NavigationViewSelected(activity));
    setupDrawerButton(activity);
}

From source file:Main.java

/**
 * Play video file from res folder./*from   w w w  .j  a  va 2s.c o  m*/
 * Then call video.start();
 * @param activity - current Activity
 * @param videoViewId R.id.introVideo
 * @param videoResourceId R.raw.intro - res/raw/intro.mp4
 * @return VideoView
 */
public static VideoView playVideo(Activity activity, int videoViewId, int videoResourceId,
        MediaPlayer.OnCompletionListener listener) {
    activity.getWindow().setFormat(PixelFormat.TRANSLUCENT);
    VideoView view = (VideoView) activity.findViewById(videoViewId);
    view.setVideoURI(
            Uri.parse("android.resource://" + activity.getPackageName() + File.separator + videoResourceId));
    view.setKeepScreenOn(true);
    view.setMediaController(null);
    view.setOnCompletionListener(listener);
    view.requestFocus();
    return view;
}

From source file:com.nextgis.libngui.activity.NGPreferenceActivity.java

public static boolean isMultiPane(Activity activity) {
    return activity.findViewById(R.id.header_fragment) != null;
}

From source file:com.ada.utils.Ui.java

public static <T extends View> T findView(Activity activity, int resId) {
    return (T) activity.findViewById(resId);
}

From source file:org.smssecure.smssecure.util.ViewUtil.java

@SuppressWarnings("unchecked")
public static <T extends View> T findById(@NonNull Activity parent, @IdRes int resId) {
    return (T) parent.findViewById(resId);
}

From source file:org.smssecure.smssecure.util.ViewUtil.java

public static <T extends View> Stub<T> findStubById(@NonNull Activity parent, @IdRes int resId) {
    return new Stub<T>((ViewStub) parent.findViewById(resId));
}

From source file:Main.java

public static void setHeight(final Activity root, final int viewId, final int height) {
    if (root != null) {
        setHeight(root.findViewById(viewId), height);
    }/*from  w w w. java2s  .  co m*/
}