Java Code Examples for android.view.View#setBackgroundDrawable()

The following examples show how to use android.view.View#setBackgroundDrawable() . 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: Android-Skin   File: BackgroundAttr.java    License: MIT License 6 votes vote down vote up
@Override
public void apply(View view) {
    if (view==null){
        return;
    }
    if (RES_TYPE_NAME_COLOR.equals(attrValueTypeName)) {
        view.setBackgroundColor(AndroidSkin.getInstance().getSkinColor(
                attrValueTypeName, attrValueRefName, attrValueRefId));
    } else if (RES_TYPE_NAME_DRAWABLE.equals(attrValueTypeName)) {
        Drawable bg = AndroidSkin.getInstance().getSkinDrawable(
                attrValueTypeName, attrValueRefName, attrValueRefId);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            view.setBackground(bg);
        } else {
            view.setBackgroundDrawable(bg);
        }
    }
    //LogUtils.d(TAG, "view apply ,id "+attrValueRefId+" " + attrValueTypeName+" "+attrValueRefName );
}
 
Example 2
Source Project: letv   File: HotTabPageIndicator.java    License: Apache License 2.0 6 votes vote down vote up
public void setCurrentItem(int item) {
    if (this.mViewPager != null) {
        if (!(item == -1 || this.mSelectedTabIndex == item)) {
            this.mViewPager.setCurrentItem(item);
        }
        this.mSelectedTabIndex = item;
        int tabCount = this.mTabLayout.getChildCount();
        int i = 0;
        while (i < tabCount) {
            View child = this.mTabLayout.getChildAt(i);
            boolean isSelected = i == item;
            child.setSelected(isSelected);
            if (isSelected) {
                animateToTab(item);
                ((TabView) child).setTextColor(this.mContext.getResources().getColor(2131493202));
                child.setBackgroundResource(2130839011);
            } else {
                ((TabView) child).setTextColor(this.mContext.getResources().getColor(2131493237));
                child.setBackgroundDrawable(null);
            }
            i++;
        }
    }
}
 
Example 3
Source Project: UltimateAndroid   File: Sections.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final int type = getItemViewType(position);

    View v = null;
    if (convertView != null) {
        Log.d("mobeta", "using convertView");
        v = convertView;
    } else if (type != SECTION_DIV) {
        Log.d("mobeta", "inflating normal item");
        v = mInflater.inflate(R.layout.drag_sort_listview_list_item_bg_handle, parent, false);
        v.setBackgroundDrawable(getBGDrawable(type));
    } else {
        Log.d("mobeta", "inflating section divider");
        v = mInflater.inflate(R.layout.drag_sort_listview_section_div, parent, false);
    }

    if (type != SECTION_DIV) {
        // bind data
        ((TextView) v).setText(mData.get(dataPosition(position)));
    }

    return v;
}
 
Example 4
Source Project: android-art-res   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        // test transition
        View v = findViewById(R.id.test_transition);
        TransitionDrawable drawable = (TransitionDrawable) v.getBackground();
        drawable.startTransition(1000);

        // test scale
        View testScale = findViewById(R.id.test_scale);
        ScaleDrawable testScaleDrawable = (ScaleDrawable) testScale.getBackground();
        testScaleDrawable.setLevel(10);

        // test clip
        ImageView testClip = (ImageView) findViewById(R.id.test_clip);
        ClipDrawable testClipDrawable = (ClipDrawable) testClip.getDrawable();
        testClipDrawable.setLevel(8000);
        
        // test custom drawable
        View testCustomDrawable = findViewById(R.id.test_custom_drawable);
        CustomDrawable customDrawable = new CustomDrawable(Color.parseColor("#0ac39e"));
        testCustomDrawable.setBackgroundDrawable(customDrawable);
    }
}
 
Example 5
public void addSubItem(int id, View view, int width, int height) {
    createPopupLayout();
    view.setLayoutParams(new LinearLayout.LayoutParams(width, height));
    popupLayout.addView(view);
    view.setTag(id);
    view.setOnClickListener(view1 -> {
        if (popupWindow != null && popupWindow.isShowing()) {
            if (processedPopupClick) {
                return;
            }
            processedPopupClick = true;
            popupWindow.dismiss(allowCloseAnimation);
        }
        if (parentMenu != null) {
            parentMenu.onItemClick((Integer) view1.getTag());
        } else if (delegate != null) {
            delegate.onItemClick((Integer) view1.getTag());
        }
    });
    view.setBackgroundDrawable(Theme.getSelectorDrawable(false));
}
 
Example 6
Source Project: Android-utils   File: ViewUtils.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void setBackground(View view, Drawable drawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackground(drawable);
    } else {
        view.setBackgroundDrawable(drawable);
    }
}
 
Example 7
Source Project: V.FlyoutTest   File: FragmentArgumentsSupport.java    License: MIT License 5 votes vote down vote up
/**
 * Create the view for this fragment, using the arguments given to it.
 */
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.hello_world, container, false);
    View tv = v.findViewById(R.id.text);
    ((TextView)tv).setText(mLabel != null ? mLabel : "(no label)");
    tv.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.gallery_thumb));
    return v;
}
 
Example 8
Source Project: guanggoo-android   File: MenuItemBadge.java    License: Apache License 2.0 5 votes vote down vote up
public static void setBackgroundCompat(View v, Drawable d) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
        v.setBackgroundDrawable(d);
    } else {
        v.setBackground(d);
    }
}
 
Example 9
Source Project: DialogSheet   File: DialogSheet.java    License: MIT License 5 votes vote down vote up
public DialogSheet setRoundedCorners(boolean roundedCorners) {
    if (!roundedCorners) {
        View bgView = bottomSheetDialog.findViewById(R.id.mainDialogContainer);
        if (bgView != null)
            bgView.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.dialog_sheet_main_background));
    }

    return this;
}
 
Example 10
Source Project: injor   File: BackroundProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void process(final View view, String resName, ResourceManager resourceManager, boolean isInUiThread) {
	final Drawable drawable = resourceManager.getDrawable(resName);
	if (drawable != null) {
		if (isInUiThread) {
			view.setBackgroundDrawable(drawable);
		} else {
			UITaskManager.getInstance().post(new Runnable() {
				@Override
				public void run() {
					view.setBackgroundDrawable(drawable);
				}
			});
		}
	} else {
		try {
			final int color = resourceManager.getColor(resName);
			if (isInUiThread) {
				view.setBackgroundColor(color);
			} else {
				UITaskManager.getInstance().post(new Runnable() {
					@Override
					public void run() {
						view.setBackgroundColor(color);
					}
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
Example 11
Source Project: Mover   File: ViewUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets background, independence of API Level
 *
 * @param view target
 * @param drawable background
 */
public static void setBackground(View view, Drawable drawable){
    if(Build.VERSION.SDK_INT > 16) {
        view.setBackground(drawable);
    }else{
        view.setBackgroundDrawable(drawable);
    }
}
 
Example 12
Source Project: Silence   File: ViewUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static void setBackground(final @NonNull View v, final @Nullable Drawable drawable) {
  if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
    v.setBackground(drawable);
  } else {
    v.setBackgroundDrawable(drawable);
  }
}
 
Example 13
/**
 * Sets a background {@link Drawable} on a view.
 * 
 * @param view
 * @param drawable
 */
@SuppressWarnings("deprecation")
public static void setBackgroundDrawable(View view, Drawable drawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackgroundJB(view, drawable);
    } else {
        view.setBackgroundDrawable(drawable);
    }
}
 
Example 14
Source Project: WelikeAndroid   File: AsyncBitmapLoader.java    License: Apache License 2.0 5 votes vote down vote up
/**
    * 将图片设置到View上
    *
    * @param bitmap
    * @param view
    */
   @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @SuppressWarnings("deprecation")
private void setImageToView(final Bitmap bitmap, final View view) {
       if (view != null) {
           if (view instanceof ImageView) {
               ((ImageView) view).setImageBitmap(bitmap);
           } else {
               if (Build.VERSION.SDK_INT > 15) {
                   view.setBackground(new BitmapDrawable(view.getResources(), bitmap));
               } else {
                   view.setBackgroundDrawable(new BitmapDrawable(view.getResources(), bitmap));
               }
           }
       }
   }
 
Example 15
Source Project: Social   File: ViewCompat.java    License: Apache License 2.0 5 votes vote down vote up
public static void setBackground(View view, Drawable background) {
	if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
		SDK16.setBackground(view, background);
	} else {
		view.setBackgroundDrawable(background);
	}
}
 
Example 16
Source Project: NewXmPluginSDK   File: SettingsItemView.java    License: Apache License 2.0 5 votes vote down vote up
public SettingsItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        LayoutInflater inflater = LayoutInflater.from(context);

        View itemView = inflater.inflate(R.layout.settings_item, null);
        mContainerView = itemView;
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        addView(itemView, lp);
        itemView.setBackgroundDrawable(getBackground());
        mTitleTextView = (TextView) itemView.findViewById(R.id.settings_item_title);
        mSubTitleTextView = (TextView) itemView.findViewById(R.id.settings_item_sub_title);
        mSwitchButton = (SwitchButton) itemView.findViewById(R.id.settings_item_switch_btn);
        mOnclickImageView = (ImageView) itemView.findViewById(R.id.settings_item_arrow);
        mInfoTextView = (TextView) itemView.findViewById(R.id.settings_item_info);
        mSelectImageView = (ImageView) itemView.findViewById(R.id.settings_item_select);
        mTitleContainer = itemView.findViewById(R.id.title_container);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SettingsItem, 0, 0);
        String title = a.getString(R.styleable.SettingsItem_item_title);
        String subTitle = a.getString(R.styleable.SettingsItem_item_subtitle);
        String info = a.getString(R.styleable.SettingsItem_item_info);
        mType = a.getInt(R.styleable.SettingsItem_item_type, 1);
        mSelected = a.getBoolean(R.styleable.SettingsItem_item_select, false);
        int lineMargin = a.getDimensionPixelSize(R.styleable.SettingsItem_item_line_margin, 0);
        a.recycle();

        setTitle(title);
        setSubTitle(subTitle);
        setInfo(info);
        setType(mType);

        View view = new View(getContext());
        view.setBackgroundColor(0xffe5e5e5);
        lp = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, 1);
        lp.gravity = Gravity.BOTTOM;
//        int marging = getResources().getDimensionPixelOffset(R.dimen.settings_item_margin);
        lp.setMargins(lineMargin, 0, lineMargin, 0);
        addView(view, lp);
    }
 
Example 17
Source Project: Genius-Android   File: UiCompat.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * android.support.v4.view.ViewCompat SHOULD include this once and for all!!
 * But it doesn't...
 *
 * @param view       View
 * @param background DrawableBackground
 */
@SuppressWarnings("deprecation")
public static void setBackground(View view, Drawable background) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        UiCompatNotCrash.setBackground(view, background);
    } else {
        view.setBackgroundDrawable(background);
    }
}
 
Example 18
Source Project: Abelana-Android   File: PickerFragment.java    License: Apache License 2.0 4 votes vote down vote up
private void inflateTitleBar(ViewGroup view) {
    ViewStub stub = (ViewStub) view.findViewById(R.id.com_facebook_picker_title_bar_stub);
    if (stub != null) {
        View titleBar = stub.inflate();

        final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.MATCH_PARENT);
        layoutParams.addRule(RelativeLayout.BELOW, R.id.com_facebook_picker_title_bar);
        listView.setLayoutParams(layoutParams);

        if (titleBarBackground != null) {
            titleBar.setBackgroundDrawable(titleBarBackground);
        }

        doneButton = (Button) view.findViewById(R.id.com_facebook_picker_done_button);
        if (doneButton != null) {
            doneButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    logAppEvents(true);
                    appEventsLogged = true;

                    if (onDoneButtonClickedListener != null) {
                        onDoneButtonClickedListener.onDoneButtonClicked(PickerFragment.this);
                    }
                }
            });

            if (getDoneButtonText() != null) {
                doneButton.setText(getDoneButtonText());
            }

            if (doneButtonBackground != null) {
                doneButton.setBackgroundDrawable(doneButtonBackground);
            }
        }

        titleTextView = (TextView) view.findViewById(R.id.com_facebook_picker_title);
        if (titleTextView != null) {
            if (getTitleText() != null) {
                titleTextView.setText(getTitleText());
            }
        }
    }
}
 
Example 19
Source Project: FireFiles   File: Utils.java    License: Apache License 2.0 4 votes vote down vote up
public static void tintWidget(View view, int color) {
    Drawable wrappedDrawable = DrawableCompat.wrap(view.getBackground());
    DrawableCompat.setTint(wrappedDrawable.mutate(), color);
    view.setBackgroundDrawable(wrappedDrawable);
}
 
Example 20
private void setBackgroundCompat(View view, Drawable d) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        view.setBackground(d);
    else view.setBackgroundDrawable(d);
}