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

The following examples show how to use android.view.ViewGroup#setBackgroundResource() . 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: SwipeBackLayout.java    From Android-Application-ZJB with Apache License 2.0 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 2
Source File: SwipeBackLayout.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 3
Source File: SwipeBackLayout.java    From ExpressHelper with GNU General Public License v3.0 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    LayoutParams p = (LayoutParams) decorChild.getLayoutParams();
    FrameLayout newRoot = new FrameLayout(getContext());
    decor.removeView(decorChild);
    newRoot.addView(decorChild, p);
    p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    addView(newRoot, p);
    setContentView(newRoot);
    setLayoutParams(p);
    decor.addView(this, p);
}
 
Example 4
Source File: SwipeBackLayout.java    From UltimateSwipeTool with Apache License 2.0 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();
    //replace decorView child
    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    //set background must
    decorChild.setBackgroundResource(background);

    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);

}
 
Example 5
Source File: RobotoCalendarView.java    From roboto-calendar-view with Apache License 2.0 6 votes vote down vote up
public void clearSelectedDay() {
    if (lastSelectedDayCalendar != null) {
        ViewGroup dayOfTheMonthBackground = getDayOfMonthBackground(lastSelectedDayCalendar);

        // If it's today, keep the current day style
        Calendar nowCalendar = Calendar.getInstance();
        if (nowCalendar.get(Calendar.YEAR) == lastSelectedDayCalendar.get(Calendar.YEAR) && nowCalendar.get(Calendar.DAY_OF_YEAR) == lastSelectedDayCalendar.get(Calendar.DAY_OF_YEAR)) {
            dayOfTheMonthBackground.setBackgroundResource(R.drawable.ring);
        } else {
            dayOfTheMonthBackground.setBackgroundResource(android.R.color.transparent);
        }

        TextView dayOfTheMonth = getDayOfMonthText(lastSelectedDayCalendar);
        dayOfTheMonth.setTextColor(ContextCompat.getColor(getContext(), R.color.roboto_calendar_day_of_the_month_font));

        ImageView circleImage1 = getCircleImage1(lastSelectedDayCalendar);
        ImageView circleImage2 = getCircleImage2(lastSelectedDayCalendar);
        if (circleImage1.getVisibility() == VISIBLE) {
            DrawableCompat.setTint(circleImage1.getDrawable(), ContextCompat.getColor(getContext(), R.color.roboto_calendar_circle_1));
        }

        if (circleImage2.getVisibility() == VISIBLE) {
            DrawableCompat.setTint(circleImage2.getDrawable(), ContextCompat.getColor(getContext(), R.color.roboto_calendar_circle_2));
        }
    }
}
 
Example 6
Source File: DayStyleFactory.java    From holo-calendar with Apache License 2.0 6 votes vote down vote up
public static ViewGroup getDayLayoutForStyle(final LayoutInflater inflater, final ViewGroup parent,
                                             final int dayStyle) {

    switch(dayStyle) {
        case DAY_STYLE_TILED:
            // Inflate the layout, and add the background resource
            final ViewGroup dayLayout = (ViewGroup) inflater.inflate(R.layout.lib_calendar_day, parent, false);
            dayLayout.setBackgroundResource(R.drawable.lib_calendar_background);
            return dayLayout;

        case DAY_STYLE_FLAT:
            // Inflate te layout, and return it
            return (ViewGroup) inflater.inflate(R.layout.lib_calendar_day, parent, false);

        default:
            // Invalid style, throw exception
            throw new IllegalArgumentException("Day Style is invalid, cannot inflate day layout.");
    }
}
 
Example 7
Source File: SwipeBackLayout.java    From SwipeBackFragment with Apache License 2.0 6 votes vote down vote up
public void attachToActivity(FragmentActivity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 8
Source File: SwipeBackLayout.java    From CoreModule with Apache License 2.0 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 9
Source File: SwipeBackLayout.java    From MicroReader with MIT License 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    //6.0.1=1测试状态栏和滑动返回冲突
    //Log.i("TAG", activity.getClass().getName() + ":" + decor.getChildCount());
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 10
Source File: SwipeBackLayout.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public void attachToActivity(FragmentActivity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 11
Source File: SwipeBackLayout.java    From SimplifyReader with Apache License 2.0 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 12
Source File: SwipeBackLayout.java    From SimpleNews with Apache License 2.0 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 13
Source File: SwipeBackLayout.java    From MaterialQQLite with Apache License 2.0 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 14
Source File: HashtagView.java    From hashtag-view with MIT License 6 votes vote down vote up
private View inflateItemView(final ItemData item) {
    ViewGroup itemLayout = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.layout_item, this, false);
    itemLayout.setBackgroundResource(backgroundDrawable);
    itemLayout.setPadding(itemPaddingLeft, itemPaddingTop, itemPaddingRight, itemPaddingBottom);
    itemLayout.setMinimumWidth(minItemWidth);
    try {
        if (foregroundDrawable != 0)
            ((FrameLayout) itemLayout).setForeground(ContextCompat.getDrawable(getContext(), foregroundDrawable));
    } catch (Exception e) {
        e.printStackTrace();
    }

    itemLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isInSelectMode) {
                handleSelection(item);
            } else {
                handleClick(item);
            }
        }
    });
    return itemLayout;
}
 
Example 15
Source File: SwipeBackLayout.java    From hipda with GNU General Public License v2.0 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 16
Source File: CustomizeViews.java    From placeholderj with Apache License 2.0 5 votes vote down vote up
private void customizeViewEmpty(ViewGroup viewEmpty, ImageView viewEmptyImage,
                                TextView viewEmptyMessage, Button viewEmptyTryAgainButton) {
    if (viewEmpty != null) {
        if (mPlaceHolderManager.mViewEmptyBackgroundColor != 0) {
            viewEmpty.setBackgroundColor(getColor(mPlaceHolderManager.mViewEmptyBackgroundColor));
        } else if (mPlaceHolderManager.mViewEmptyBackgroundResource > 0) {
            viewEmpty.setBackgroundResource(mPlaceHolderManager.mViewEmptyBackgroundResource);
        }
        if (mPlaceHolderManager.mViewEmptyText > 0) {
            viewEmptyMessage.setText(mPlaceHolderManager.mViewEmptyText);
        }
        if (mPlaceHolderManager.mViewEmptyTextSize > 0) {
            setTextSize(viewEmptyMessage, mPlaceHolderManager.mViewEmptyTextSize);
        }
        if (mPlaceHolderManager.mViewEmptyTextColor != 0) {
            viewEmptyMessage.setTextColor(getColor(mPlaceHolderManager.mViewEmptyTextColor));
        }
        if (mPlaceHolderManager.mViewEmptyTryAgainButtonText > 0) {
            viewEmptyTryAgainButton.setText(mPlaceHolderManager.mViewEmptyTryAgainButtonText);
        }
        if (mPlaceHolderManager.mViewEmptyTryAgainButtonTextColor > 0) {
            viewEmptyTryAgainButton.setTextColor(mPlaceHolderManager.mViewEmptyTryAgainButtonTextColor);
        }
        if (mPlaceHolderManager.mViewEmptyTryAgainButtonBackgroundResource > 0) {
            int backgroundRes = mPlaceHolderManager.mViewEmptyTryAgainButtonBackgroundResource;
            viewEmptyTryAgainButton.setBackgroundResource(backgroundRes);
        }
        if (mPlaceHolderManager.mViewEmptyImage > 0) {
            viewEmptyImage.setImageDrawable(getDrawable(mPlaceHolderManager.mViewEmptyImage));
        }
    }
}
 
Example 17
Source File: NavigationFragment.java    From ZhihuDaily with Apache License 2.0 5 votes vote down vote up
public void refreshUI() {
    TypedValue headerBackground = new TypedValue();
    TypedValue navdrawerBackground = new TypedValue();
    TypedValue navdrawerTextColor = new TypedValue();
    Resources.Theme theme = getActivity().getTheme();
    theme.resolveAttribute(R.attr.colorPrimaryDark, headerBackground, true);
    theme.resolveAttribute(R.attr.navdrawer_background, navdrawerBackground,true);
    theme.resolveAttribute(R.attr.navdrawer_text_color, navdrawerTextColor, true);

    recyclerView.setBackgroundResource(navdrawerBackground.resourceId);
    int childCount = recyclerView.getChildCount();
    for (int childIndex = 0; childIndex < childCount; childIndex++) {
        int viewType = mAdapter.getItemViewType(childIndex);
        switch (viewType) {
            case NavigationDrawerAdapter.Type.TYPE_HEADER:
                ViewGroup header = (ViewGroup) recyclerView.getChildAt(childIndex);
                header.setBackgroundResource(headerBackground.resourceId);
                break;
            case NavigationDrawerAdapter.Type.TYPE_ITEM:
                ViewGroup item = (ViewGroup) recyclerView.getChildAt(childIndex);
                TextView textView = (TextView) item.findViewById(R.id.tvItemName);
                textView.setTextColor(navdrawerTextColor.resourceId);
                break;
            case NavigationDrawerAdapter.Type.TYPE_BOTTOM_SPACE:
                View childView = recyclerView.getChildAt(childIndex);
                childView.setBackgroundResource(navdrawerBackground.resourceId);
                break;
        }
    }
    mAdapter.notifyDataSetChanged();
}
 
Example 18
Source File: SwipeBackLayout.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
public void attachToActivity(Activity activity) {
	mActivity = activity;
	TypedArray a = activity.getTheme().obtainStyledAttributes(
			new int[] { android.R.attr.windowBackground });
	int background = a.getResourceId(0, 0);
	a.recycle();

	ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
	ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
	decorChild.setBackgroundResource(background);
	decor.removeView(decorChild);
	addView(decorChild);
	setContentView(decorChild);
	decor.addView(this);
}
 
Example 19
Source File: GeoARActivity.java    From geoar-app with Apache License 2.0 4 votes vote down vote up
private PopupWindow getPopup() {
	if (mPopup == null) {
		ViewGroup layout = (ViewGroup) mInflater.inflate(
				R.layout.datasource_list_window, null);

		mListView = (ExpandableListView) layout
				.findViewById(R.id.expandableListView);

		Button moreButton = (Button) layout
				.findViewById(R.id.buttonMore);

		DataSourceListAdapter sourceListAdapter = new DataSourceListAdapter(
				GeoARActivity.this, mListView, visualizationClass);
		mListView.setAdapter(sourceListAdapter);
		IntroController.addViewToStep(9, mListView.getChildAt(mListView.getFirstVisiblePosition()));
		mListView.setGroupIndicator(null);

		// Click event for "More" button
		moreButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				showFragment(mPluginFragment);
				mPopup.dismiss();
			}
		});

		mPopup = new ActionProviderPopupWindow(layout);
		mPopup.setTouchable(true);
		mPopup.setOutsideTouchable(true);

		TypedArray typedArray = obtainStyledAttributes(new int[] { R.attr.actionDropDownStyle });
		int resId = typedArray.getResourceId(0, 0);
		typedArray = obtainStyledAttributes(resId,
				new int[] { android.R.attr.popupBackground });
		mPopup.setBackgroundDrawable(new BitmapDrawable(getResources()));
		layout.setBackgroundResource(typedArray.getResourceId(0, 0));
		// mPopup.setBackgroundDrawable(typedArray.getDrawable(0));
		mPopup.setWindowLayoutMode(0, LayoutParams.WRAP_CONTENT);

		// Set width of menu
		mPopup.setWidth((int) TypedValue.applyDimension(
				TypedValue.COMPLEX_UNIT_DIP, 250, getResources()
						.getDisplayMetrics()));

	}
	return mPopup;
}
 
Example 20
Source File: ImsakiyeFragment.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.vakit_imsakiye, parent, false);
    }
    ViewGroup v = (ViewGroup) convertView;
    CharSequence[] a;
    if (position == 0) {
        a = new String[]{getString(R.string.date), getString(R.string.fajr), getString(R.string.sun), getString(R.string.zuhr), getString(R.string.asr), getString(R.string.maghrib), getString(R.string.ishaa)};
    } else if (times == null) {
        a = new String[]{"00:00", "00:00", "00:00", "00:00", "00:00", "00:00", "00:00"};
    } else {
        LocalDate cal = (LocalDate) getItem(position - 1);

        LocalDateTime[] daytimes = {
                times.getTime(cal, Vakit.FAJR.ordinal()),
                times.getTime(cal, Vakit.SUN.ordinal()),
                times.getTime(cal, Vakit.DHUHR.ordinal()),
                times.getTime(cal, Vakit.ASR.ordinal()),
                times.getTime(cal, Vakit.MAGHRIB.ordinal()),
                times.getTime(cal, Vakit.ISHAA.ordinal())};

        a = new CharSequence[]{cal.toString("dd.MM"),
                LocaleUtils.formatTimeForHTML(daytimes[0].toLocalTime()),
                LocaleUtils.formatTimeForHTML(daytimes[1].toLocalTime()),
                LocaleUtils.formatTimeForHTML(daytimes[2].toLocalTime()),
                LocaleUtils.formatTimeForHTML(daytimes[3].toLocalTime()),
                LocaleUtils.formatTimeForHTML(daytimes[4].toLocalTime()),
                LocaleUtils.formatTimeForHTML(daytimes[5].toLocalTime())};
    }

    for (int i = 0; i < 7; i++) {
        TextView tv = (TextView) v.getChildAt(i);
        tv.setText(a[i]);
    }
    if (position == today) {
        v.setBackgroundResource(R.color.colorPrimary);
    } else if (position == 0) {
        v.setBackgroundResource(R.color.accent);
    } else if ((position % 2) == 0) {
        v.setBackgroundResource(R.color.colorPrimaryLight);
    } else {
        v.setBackgroundResource(R.color.background);
    }

    return v;
}