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:Main.java

public static void setFitsSystemWindows(Activity activity, boolean values) {
    ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
    Log.d("statusbar", "rootViewid  " + rootView.getId());
    rootView.setFitsSystemWindows(values);
    rootView.setClipToPadding(true);//www  .ja va  2  s  .c  o  m
}

From source file:Main.java

public static void updateLeftTitle(Activity activity, int viewId, String text) {
    View view = activity.findViewById(viewId);
    if (view == null) {
        return;//from   w w  w .j  a  v  a  2s  .  c  om
    }
    if (view instanceof TextView) {
        ((TextView) view).setText(text);
    }
}

From source file:Main.java

public static void updateTitle(Activity activity, int viewId, String title) {
    TextView view = (TextView) activity.findViewById(viewId);
    updateTitle(view, title);//ww w  .j  a va 2  s  .com
}

From source file:Main.java

public static void updateRightImgTitle(Activity activity, int viewId, int txtRes, int imgRes) {
    View view = activity.findViewById(viewId);
    if (view == null) {
        return;/*from w  w  w  .  j  ava 2 s.com*/
    }
    if (view instanceof TextView) {
        view.setVisibility(View.VISIBLE);
        ((TextView) view).setText(activity.getString(txtRes));
        Drawable drawable = activity.getResources().getDrawable(imgRes);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        ((TextView) view).setCompoundDrawables(null, drawable, null, null);
    }
}

From source file:Main.java

public static void updateLeftTitle(Activity activity, int viewId, int resource) {
    View view = activity.findViewById(viewId);
    if (view == null) {
        return;/*  w w  w  .  j  a  va  2 s . com*/
    }
    if (view instanceof TextView) {
        ((TextView) view).setText(activity.getString(resource));
    }
}

From source file:Main.java

public static <E extends View> E findViewById(Activity activity, @IdRes int resId) {
    //noinspection unchecked
    return (E) activity.findViewById(resId);
}

From source file:Main.java

public static int getActivityWidth(Activity context) {
    if (context == null) {
        return 0;
    }//from  ww w  .  j  ava  2s.c  o m
    return context.findViewById(android.R.id.content).getWidth();
}

From source file:Main.java

public static int getActivityHeight(Activity context) {
    if (context == null) {
        return 0;
    }/*from   w  w w . ja va 2  s.  c om*/
    return context.findViewById(android.R.id.content).getHeight();
}

From source file:Main.java

public static void updateTitle(Activity activity, int viewId, int resourceId) {
    TextView view = (TextView) activity.findViewById(viewId);
    String title = activity.getString(resourceId);
    updateTitle(view, title);//from ww  w.  jav  a 2 s  . c  o  m
}

From source file:Main.java

public static <V> V findViewById(@NonNull final Activity activity, final int id) {
    //noinspection unchecked
    return (V) activity.findViewById(id);
}