List of usage examples for android.view View setBackgroundDrawable
@Deprecated public void setBackgroundDrawable(Drawable background)
From source file:Main.java
/** * Set the background of a {@link android.view.View} to the specified color, with a darker version of the * color as a border.//w ww . j av a 2 s. c o m */ public static void setViewBackground(View view, int color) { Resources r = view.getResources(); Drawable currentDrawable = view.getBackground(); GradientDrawable backgroundDrawable; if (currentDrawable != null && currentDrawable instanceof GradientDrawable) { // Reuse drawable backgroundDrawable = (GradientDrawable) currentDrawable; } else { backgroundDrawable = new GradientDrawable(); } int darkenedColor = darkenColor(color); backgroundDrawable.setColor(color); backgroundDrawable.setStroke( (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics()), darkenedColor); view.setBackgroundDrawable(backgroundDrawable); }
From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java
public static void setViewBackground(View view, Drawable bg) { int paddingL = view.getPaddingLeft(); int paddingT = view.getPaddingTop(); int paddingR = view.getPaddingRight(); int paddingB = view.getPaddingBottom(); if (isApi_16_OrHigher()) { view.setBackground(bg);//from w w w. ja v a2s. com } else { //noinspection deprecation view.setBackgroundDrawable(bg); } view.setPadding(paddingL, paddingT, paddingR, paddingB); }
From source file:com.fastbootmobile.encore.utils.Utils.java
/** * Provides an API-independent way to set a Drawable background on a view *///from w ww .ja va 2 s.c o m public static void setViewBackground(View v, Drawable d) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { v.setBackground(d); } else { v.setBackgroundDrawable(d); } }
From source file:com.apptentive.android.sdk.util.Util.java
/** * helper method to set the background depending on the android version * * @param v//from w w w. ja va 2 s .c o m * @param d */ public static void setBackground(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); } }
From source file:com.android.cards.view.helper.CardViewHelperImplBase.java
@Override public void setBackground(View view, Drawable drawable) { if (view != null) view.setBackgroundDrawable(drawable); }
From source file:com.example.testapp.CountingFragment.java
/** * The Fragment's UI is just a simple text view showing its instance number. *///from www. j a v a 2 s . c om @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("Fragment #" + mNum); tv.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.gallery_thumb)); return v; }
From source file:com.intirix.cloudpasswordmanager.pages.settings.SavePasswordOptionsViewHolder.java
private void setBackground(View view, int resource) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { view.setBackgroundDrawable(view.getResources().getDrawable(resource)); } else {/*from w w w . j a v a 2 s .c o m*/ view.setBackground(view.getResources().getDrawable(resource)); } }
From source file:org.solovyev.android.messenger.DefaultMultiPaneManager.java
@Override public void onCreatePane(@Nonnull Activity activity, @Nullable View paneParent, @Nonnull View pane) { if (this.isDualPane(activity)) { if (this.isFirstPane(paneParent)) { pane.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.mpp_border_right)); // border may add padding => set to zeros pane.setPadding(0, 0, 0, 0); } else if (this.isSecondPane(paneParent)) { // activity background should be used } else if (this.isTriplePane(activity) && this.isThirdPane(paneParent)) { if (Views.getScreenOrientation(activity) == Configuration.ORIENTATION_LANDSCAPE) { pane.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.mpp_border_left)); }//from www. j a va 2 s .c o m } } }
From source file:de.Maxr1998.maxlock.thememanager.navigation.drawer.NavigationDrawerFragment.java
public void setUp(DrawerLayout drawerLayout, Toolbar toolbar) { mDrawerLayout = drawerLayout;// w w w . j a v a 2s .co m mDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, toolbar, R.string.app_name, R.string.app_name) { @Override public void onDrawerOpened(View drawerView) { if (themeListFragment != null) themeListFragment.hideBottomBar(true); super.onDrawerOpened(drawerView); PreferenceManager.getDefaultSharedPreferences(getActivity()).edit() .putBoolean(Common.USER_LEARNED_DRAWER, true).apply(); //getActivity().invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (themeListFragment != null) themeListFragment.reShowBottomBar(); //getActivity().invalidateOptionsMenu(); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); if (!PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean(Common.USER_LEARNED_DRAWER, false) && !mFromSavedInstanceState) mDrawerLayout.openDrawer(getActivity().findViewById(R.id.scrimInsetsFrameLayout)); final View[] drawerItems = { drawerView.findViewById(R.id.installed_themes), drawerView.findViewById(R.id.wiki) }; for (View drawerItem : drawerItems) { drawerItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { for (View v : drawerItems) { v.setBackgroundDrawable(getResources().getDrawable(R.drawable.selectable_item_background)); ((TextView) v).setTextColor(getResources().getColor(R.color.drawer_text_color)); } displayView(view); } }); } displayView(drawerItems[0]); }
From source file:de.tudarmstadt.informatik.secuso.phishedu2.LevelSelectorActivity.java
@Override protected View getPage(int level, LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (level > 0 && Constants.SKIP_LEVEL1) { level++;/*from www. j a v a 2s .co m*/ } NoPhishLevelInfo level_info = BackendControllerImpl.getInstance().getLevelInfo(level); View layoutView = inflater.inflate(R.layout.fragment_level_overview_template, container, false); int userlevel = BackendControllerImpl.getInstance().getMaxUnlockedLevel(); View button = layoutView.findViewById(R.id.levelbutton); if (level <= userlevel) { button.setBackgroundDrawable(getResources().getDrawable(R.drawable.levelicon_active_bg)); layoutView.findViewById(R.id.levelbutton_padlock).setVisibility(View.INVISIBLE); if (BackendControllerImpl.getInstance().getLevelCompleted(level)) { layoutView.findViewById(R.id.levelbutton_tick).setVisibility(View.VISIBLE); layoutView.findViewById(R.id.levelbutton_points).setVisibility(View.VISIBLE); layoutView.findViewById(R.id.levelbutton_points_text).setVisibility(View.VISIBLE); } else { layoutView.findViewById(R.id.levelbutton_tick).setVisibility(View.INVISIBLE); layoutView.findViewById(R.id.levelbutton_points).setVisibility(View.INVISIBLE); layoutView.findViewById(R.id.levelbutton_points_text).setVisibility(View.INVISIBLE); } if (level_info.showStars()) { showStars(layoutView, BackendControllerImpl.getInstance().getLevelStars(level)); } else { hideStars(layoutView); } } else { button.setBackgroundDrawable(getResources().getDrawable(R.drawable.levelicon_inactive_bg)); layoutView.findViewById(R.id.levelbutton_padlock).setVisibility(View.VISIBLE); layoutView.findViewById(R.id.levelbutton_tick).setVisibility(View.INVISIBLE); layoutView.findViewById(R.id.levelbutton_points).setVisibility(View.INVISIBLE); layoutView.findViewById(R.id.levelbutton_points_text).setVisibility(View.INVISIBLE); if (level_info.showStars()) { showStars(layoutView, 0); } else { hideStars(layoutView); } } TextView levelnumber = (TextView) layoutView.findViewById(R.id.levelbutton_text); levelnumber.setText(level_info.getLevelNumber()); TextView levelTitle = (TextView) layoutView.findViewById(R.id.level_title); levelTitle.setText(level_info.titleId); TextView levelDescription = (TextView) layoutView.findViewById(R.id.level_description); levelDescription.setText(level_info.subTitleId); ((TextView) layoutView.findViewById(R.id.levelbutton_points)) .setText(Integer.toString(BackendControllerImpl.getInstance().getLevelPoints(level))); if (level <= 1 || level == 11) { layoutView.findViewById(R.id.levelbutton_points).setVisibility(View.INVISIBLE); layoutView.findViewById(R.id.levelbutton_points_text).setVisibility(View.INVISIBLE); } return layoutView; }