Java Code Examples for android.widget.FrameLayout#setBackground()

The following examples show how to use android.widget.FrameLayout#setBackground() . 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: BottomSheetContainer.java    From bottomsheets with Apache License 2.0 6 votes vote down vote up
private void initBottomSheet() {
    mBottomSheetView = new FrameLayout(getContext());
    mBottomSheetView.setLayoutParams(generateDefaultLayoutParams());
    mBottomSheetView.setBackground(createBottomSheetBackgroundDrawable());
    mBottomSheetView.setPadding(
        mBottomSheetView.getPaddingLeft(),
        ((int) mConfig.getExtraPaddingTop()),
        mBottomSheetView.getPaddingRight(),
        ((int) mConfig.getExtraPaddingBottom())
    );

    // Creating the actual sheet content view
    final View createdSheetView = Preconditions.checkNonNull(onCreateSheetContentView(getContext()));

    // adding the created views
    mBottomSheetView.addView(createdSheetView);
    addView(mBottomSheetView);
}
 
Example 2
Source File: DottedGridView.java    From mirror with Apache License 2.0 6 votes vote down vote up
private void initializeLayout(Context context) {
    mViews = new LinkedHashSet<>();

    FrameLayout gridLayout = new FrameLayout(context);
    gridLayout.setBackground(ContextCompat.getDrawable(context, R.drawable.bg_dotted_grid));
    gridLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));

    mBackground = new FrameLayout(context);
    mBackground.addView(gridLayout);
    mBackground.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
    mBackground.setBackground(ContextCompat.getDrawable(context, R.drawable.bg_solid_border));
    mBackground.setVisibility(INVISIBLE);
    addView(mBackground);

    // now set the child clipping to false
    setClipChildren(false);
}
 
Example 3
Source File: MessageInternalUserTextViewHolder.java    From SlyceMessaging with MIT License 6 votes vote down vote up
public MessageInternalUserTextViewHolder(View itemView, CustomSettings customSettings) {
    super(itemView, customSettings);

    avatar = (ImageView) itemView.findViewById(R.id.message_user_text_image_view_avatar);
    carrot = (ImageView) itemView.findViewById(R.id.message_user_text_image_view_carrot);
    initials = (TextView) itemView.findViewById(R.id.message_user_text_text_view_initials);
    text = (TextView) itemView.findViewById(R.id.message_user_text_text_view_text);
    timestamp = (TextView) itemView.findViewById(R.id.message_user_text_text_view_timestamp);
    avatarContainer = (ViewGroup) itemView.findViewById(R.id.message_user_text_view_group_avatar);
    bubble = (FrameLayout) itemView.findViewById(R.id.message_user_text_view_group_bubble);

    Drawable drawable = ContextCompat.getDrawable(itemView.getContext(), R.drawable.shape_rounded_rectangle_white);
    // Drawable drawable = itemView.getContext().getDrawable();
    drawable.setColorFilter(customSettings.localBubbleBackgroundColor, PorterDuff.Mode.SRC_ATOP);
    bubble.setBackground(drawable);
    carrot.setColorFilter(customSettings.localBubbleBackgroundColor);
    text.setTextColor(customSettings.localBubbleTextColor);
    timestamp.setTextColor(customSettings.timestampColor);
}
 
Example 4
Source File: MessageExternalUserTextViewHolder.java    From SlyceMessaging with MIT License 6 votes vote down vote up
public MessageExternalUserTextViewHolder(View itemView, final CustomSettings customSettings) {
    super(itemView, customSettings);

    avatar = (ImageView) itemView.findViewById(R.id.message_scout_text_image_view_avatar);
    carrot = (ImageView) itemView.findViewById(R.id.message_scout_text_image_view_carrot);
    text = (TextView) itemView.findViewById(R.id.message_scout_text_text_view_text);
    timestamp = (TextView) itemView.findViewById(R.id.message_scout_text_text_view_timestamp);
    avatarContainer = (ViewGroup) itemView.findViewById(R.id.message_scout_text_image_view_avatar_group);
    initials = (TextView) itemView.findViewById(R.id.message_scout_text_text_view_initials);
    bubble = (FrameLayout) itemView.findViewById(R.id.message_scout_text_view_group_bubble);

    Drawable drawable = ContextCompat.getDrawable(itemView.getContext(), R.drawable.shape_rounded_rectangle_white);
    // Drawable drawable = itemView.getContext().getDrawable();
    drawable.setColorFilter(customSettings.externalBubbleBackgroundColor, PorterDuff.Mode.SRC_ATOP);
    bubble.setBackground(drawable);
    carrot.setColorFilter(customSettings.externalBubbleBackgroundColor);
    text.setTextColor(customSettings.externalBubbleTextColor);
    timestamp.setTextColor(customSettings.timestampColor);
}
 
Example 5
Source File: Watermark.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 显示水印,铺满整个页面
 *
 * @param activity 活动
 * @param text     水印
 */
public void show(Activity activity, String text) {
    WatermarkDrawable drawable = new WatermarkDrawable();
    drawable.mText = text;
    drawable.mTextColor = mTextColor;
    drawable.mTextSize = mTextSize;
    drawable.mRotation = mRotation;

    ViewGroup rootView = activity.findViewById(android.R.id.content);
    FrameLayout layout = new FrameLayout(activity);
    layout.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    layout.setBackground(drawable);
    rootView.addView(layout);
}
 
Example 6
Source File: Tips.java    From BaseRecyclerViewAdapterHelper with MIT License 5 votes vote down vote up
/**
 * 创建自定义 Toast View
 *
 * @param message 文本消息
 * @return View
 */
private static View createTextToastView(String message) {
    // 画圆角矩形背景
    float rc = dp2px(6);
    RoundRectShape shape = new RoundRectShape(new float[]{rc, rc, rc, rc, rc, rc, rc, rc}, null, null);
    ShapeDrawable drawable = new ShapeDrawable(shape);
    drawable.getPaint().setColor(Color.argb(225, 240, 240, 240));
    drawable.getPaint().setStyle(Paint.Style.FILL);
    drawable.getPaint().setAntiAlias(true);
    drawable.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG);

    // 创建View
    FrameLayout layout = new FrameLayout(Utils.getContext());
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layout.setLayoutParams(layoutParams);
    layout.setPadding(dp2px(16), dp2px(12), dp2px(16), dp2px(12));
    layout.setBackground(drawable);

    TextView textView = new TextView(Utils.getContext());
    textView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT));
    textView.setTextSize(15);
    textView.setText(message);
    textView.setLineSpacing(dp2px(4), 1f);
    textView.setTextColor(Color.BLACK);

    layout.addView(textView);

    return layout;
}
 
Example 7
Source File: IntermediateActivity.java    From PkRequestManager with MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private void selectCard(boolean Selected, FrameLayout Card)
{
	// Use new API beyond Jelly Bean but keep compatibility with ICS
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
		Card.setBackgroundDrawable(Selected ? mRes.getDrawable(R.drawable.card_bg_selected) : mRes.getDrawable(R.drawable.card_bg));
	}
	else {
		Card.setBackground(Selected ? mRes.getDrawable(R.drawable.card_bg_selected) : mRes.getDrawable(R.drawable.card_bg));
	}
}
 
Example 8
Source File: AdvancedActivity.java    From PkRequestManager with MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private void selectCard(boolean Selected, FrameLayout Card)
{
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
		Card.setBackgroundDrawable(Selected ? mRes.getDrawable(R.drawable.card_bg_selected) : mRes.getDrawable(R.drawable.card_bg));
	else
		Card.setBackground(Selected ? mRes.getDrawable(R.drawable.card_bg_selected) : mRes.getDrawable(R.drawable.card_bg));
}
 
Example 9
Source File: YTutils.java    From YTPlayer with GNU General Public License v3.0 4 votes vote down vote up
public static void setBackroundTint(FrameLayout frameLayout, int color) {
    Drawable buttonDrawable = frameLayout.getBackground();
    buttonDrawable = DrawableCompat.wrap(buttonDrawable);
    DrawableCompat.setTint(buttonDrawable, color);
    frameLayout.setBackground(buttonDrawable);
}
 
Example 10
Source File: TrashView.java    From dingo with GNU General Public License v3.0 4 votes vote down vote up
/**
 * コンストラクタ
 *
 * @param context Context
 */
TrashView(Context context) {
    super(context);
    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    mMetrics = new DisplayMetrics();
    mWindowManager.getDefaultDisplay().getMetrics(mMetrics);
    mAnimationHandler = new AnimationHandler(this);
    mIsEnabled = true;

    mParams = new WindowManager.LayoutParams();
    mParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    mParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
    mParams.type = OVERLAY_TYPE;
    mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
            WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    mParams.format = PixelFormat.TRANSLUCENT;
    // INFO:Windowの原点のみ左下に設定
    mParams.gravity = Gravity.LEFT | Gravity.BOTTOM;

    // 各種Viewの設定
    // TrashViewに直接貼り付けられるView(このViewを介さないと、削除Viewと背景Viewのレイアウトがなぜか崩れる)
    mRootView = new FrameLayout(context);
    mRootView.setClipChildren(false);
    // 削除アイコンのルートView
    mTrashIconRootView = new FrameLayout(context);
    mTrashIconRootView.setClipChildren(false);
    mFixedTrashIconView = new ImageView(context);
    mActionTrashIconView = new ImageView(context);
    // 背景View
    mBackgroundView = new FrameLayout(context);
    mBackgroundView.setAlpha(0.0f);
    final GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{0x00000000, 0x50000000});
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        //noinspection deprecation
        mBackgroundView.setBackgroundDrawable(gradientDrawable);
    } else {
        mBackgroundView.setBackground(gradientDrawable);
    }

    // 背景Viewの貼り付け
    final LayoutParams backgroundParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (BACKGROUND_HEIGHT * mMetrics.density));
    backgroundParams.gravity = Gravity.BOTTOM;
    mRootView.addView(mBackgroundView, backgroundParams);
    // アクションアイコンの貼り付け
    final LayoutParams actionTrashIconParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    actionTrashIconParams.gravity = Gravity.CENTER;
    mTrashIconRootView.addView(mActionTrashIconView, actionTrashIconParams);
    // 固定アイコンの貼付け
    final LayoutParams fixedTrashIconParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    fixedTrashIconParams.gravity = Gravity.CENTER;
    mTrashIconRootView.addView(mFixedTrashIconView, fixedTrashIconParams);
    // 削除アイコンの貼り付け
    final LayoutParams trashIconParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    trashIconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    mRootView.addView(mTrashIconRootView, trashIconParams);

    // TrashViewに貼り付け
    addView(mRootView);

    // 初回描画処理用
    getViewTreeObserver().addOnPreDrawListener(this);
}
 
Example 11
Source File: QtActionBar.java    From imsdk-android with MIT License 4 votes vote down vote up
public void initLeftBg()
{
    left_btn = (FrameLayout) this.findViewById(R.id.left_layout);
    left_btn.setBackground(ImageUtils.createBGSelector(wContext.get().getResources().getColor(R.color.atom_ui_primary_color),
            wContext.get().getResources().getColor(R.color.atom_ui_button_primary_color_pressed)));
}
 
Example 12
Source File: TrashView.java    From FloatingView with Apache License 2.0 4 votes vote down vote up
/**
 * コンストラクタ
 *
 * @param context Context
 */
TrashView(Context context) {
    super(context);
    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    mMetrics = new DisplayMetrics();
    mWindowManager.getDefaultDisplay().getMetrics(mMetrics);
    mAnimationHandler = new AnimationHandler(this);
    mIsEnabled = true;

    mParams = new WindowManager.LayoutParams();
    mParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    mParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
    mParams.type = OVERLAY_TYPE;
    mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
            WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    mParams.format = PixelFormat.TRANSLUCENT;
    // INFO:Windowの原点のみ左下に設定
    mParams.gravity = Gravity.LEFT | Gravity.BOTTOM;

    // 各種Viewの設定
    // TrashViewに直接貼り付けられるView(このViewを介さないと、削除Viewと背景Viewのレイアウトがなぜか崩れる)
    mRootView = new FrameLayout(context);
    mRootView.setClipChildren(false);
    // 削除アイコンのルートView
    mTrashIconRootView = new FrameLayout(context);
    mTrashIconRootView.setClipChildren(false);
    mFixedTrashIconView = new ImageView(context);
    mActionTrashIconView = new ImageView(context);
    // 背景View
    mBackgroundView = new FrameLayout(context);
    mBackgroundView.setAlpha(0.0f);
    final GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{0x00000000, 0x50000000});
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        //noinspection deprecation
        mBackgroundView.setBackgroundDrawable(gradientDrawable);
    } else {
        mBackgroundView.setBackground(gradientDrawable);
    }

    // 背景Viewの貼り付け
    final FrameLayout.LayoutParams backgroundParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (BACKGROUND_HEIGHT * mMetrics.density));
    backgroundParams.gravity = Gravity.BOTTOM;
    mRootView.addView(mBackgroundView, backgroundParams);
    // アクションアイコンの貼り付け
    final FrameLayout.LayoutParams actionTrashIconParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    actionTrashIconParams.gravity = Gravity.CENTER;
    mTrashIconRootView.addView(mActionTrashIconView, actionTrashIconParams);
    // 固定アイコンの貼付け
    final FrameLayout.LayoutParams fixedTrashIconParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    fixedTrashIconParams.gravity = Gravity.CENTER;
    mTrashIconRootView.addView(mFixedTrashIconView, fixedTrashIconParams);
    // 削除アイコンの貼り付け
    final FrameLayout.LayoutParams trashIconParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    trashIconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    mRootView.addView(mTrashIconRootView, trashIconParams);

    // TrashViewに貼り付け
    addView(mRootView);

    // 初回描画処理用
    getViewTreeObserver().addOnPreDrawListener(this);
}