Java Code Examples for android.view.View#getBackground()
The following examples show how to use
android.view.View#getBackground() .
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: Noyze File: Utils.java License: Apache License 2.0 | 6 votes |
public static void unbindDrawables(View view) { if (null == view) return; if (view.getBackground() != null) { view.getBackground().setCallback(null); view.setBackground(null); } if (view instanceof ViewGroup) { ViewGroup container = (ViewGroup) view; for (int i = 0, e = container.getChildCount(); i < e; i++) { unbindDrawables(container.getChildAt(i)); } container.removeAllViews(); } else if (view instanceof ImageView) { ImageView image = (ImageView) view; Drawable d = image.getDrawable(); if (d instanceof BitmapDrawable) { Bitmap bmp = ((BitmapDrawable) d).getBitmap(); if (null != bmp) { bmp.recycle(); } } image.setImageDrawable(null); } }
Example 2
Source Project: android-art-res File: MainActivity.java License: Apache License 2.0 | 6 votes |
@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 3
Source Project: KlyphMessenger File: UserSettingsFragment.java License: MIT License | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.com_facebook_usersettingsfragment, container, false); loginButton = (LoginButton) view.findViewById(R.id.com_facebook_usersettingsfragment_login_button); loginButton.setProperties(loginButtonProperties); loginButton.setFragment(this); loginButton.setLoginLogoutEventName(AnalyticsEvents.EVENT_USER_SETTINGS_USAGE); Session session = getSession(); if (session != null && !session.equals(Session.getActiveSession())) { loginButton.setSession(session); } connectedStateLabel = (TextView) view.findViewById(R.id.com_facebook_usersettingsfragment_profile_name); // if no background is set for some reason, then default to Facebook blue if (view.getBackground() == null) { view.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue)); } else { view.getBackground().setDither(true); } return view; }
Example 4
Source Project: aws-mobile-self-paced-labs-samples File: UserSettingsFragment.java License: Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.com_facebook_usersettingsfragment, container, false); loginButton = (LoginButton) view.findViewById(R.id.com_facebook_usersettingsfragment_login_button); loginButton.setProperties(loginButtonProperties); loginButton.setFragment(this); Session session = getSession(); if (session != null && !session.equals(Session.getActiveSession())) { loginButton.setSession(session); } connectedStateLabel = (TextView) view.findViewById(R.id.com_facebook_usersettingsfragment_profile_name); // if no background is set for some reason, then default to Facebook blue if (view.getBackground() == null) { view.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue)); } else { view.getBackground().setDither(true); } return view; }
Example 5
Source Project: ucar-weex-core File: WXViewUtils.java License: Apache License 2.0 | 6 votes |
/** * Due limitation in Android platform, the linear gradient in the following page will not be * rounded if {@link Canvas#clipPath(Path)} of the parent view invoked when API level is lower * than 21. * http://dotwe.org/weex/963c9ade129f86757cecdd85651cd30e * @param targetView * @param borderDrawable * @return */ private static boolean clipCanvasIfBackgroundImageExist(@NonNull View targetView, @NonNull BorderDrawable borderDrawable) { if (targetView instanceof ViewGroup) { View child; ViewGroup parent = ((ViewGroup) targetView); int count = parent.getChildCount(); for (int i = 0; i < count; i++) { child = parent.getChildAt(i); if (child.getBackground() instanceof BorderDrawable && ((BorderDrawable) child.getBackground()).hasImage() && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return false; } } } return true; }
Example 6
Source Project: Android-UtilCode File: ImageUtils.java License: Apache License 2.0 | 5 votes |
/** * view转Bitmap * * @param view 视图 * @return bitmap */ public static Bitmap view2Bitmap(View view) { if (view == null) return null; Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(ret); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { bgDrawable.draw(canvas); } else { canvas.drawColor(Color.WHITE); } view.draw(canvas); return ret; }
Example 7
Source Project: android-testdpc File: BaseSearchablePolicyPreferenceFragment.java License: Apache License 2.0 | 5 votes |
@Override public void onBindViewHolder(PreferenceViewHolder holder, int position) { super.onBindViewHolder(holder, position); if (position == mHighlightPosition) { View v = holder.itemView; if (v.getBackground() != null) { final int centerX = v.getWidth() / 2; final int centerY = v.getHeight() / 2; v.getBackground().setHotspot(centerX, centerY); } v.setPressed(true); v.setPressed(false); mHighlightPosition = -1; } }
Example 8
Source Project: android-proguards File: BackgroundFade.java License: Apache License 2.0 | 5 votes |
@Override public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) { if (view == null || view.getBackground() == null) return null; Drawable background = view.getBackground(); background.setAlpha(0); return ObjectAnimator.ofInt(background, ViewUtils.DRAWABLE_ALPHA, 0, 255); }
Example 9
Source Project: u2020 File: DebugDrawerLayout.java License: Apache License 2.0 | 5 votes |
private static boolean hasOpaqueBackground(View v) { final Drawable bg = v.getBackground(); if (bg != null) { return bg.getOpacity() == PixelFormat.OPAQUE; } return false; }
Example 10
Source Project: android-recipes-app File: SlidingPaneLayout.java License: Apache License 2.0 | 5 votes |
private static boolean viewIsOpaque(View v) { if (ViewCompat.isOpaque(v)) return true; // View#isOpaque didn't take all valid opaque scrollbar modes into account // before API 18 (JB-MR2). On newer devices rely solely on isOpaque above and return false // here. On older devices, check the view's background drawable directly as a fallback. if (Build.VERSION.SDK_INT >= 18) return false; final Drawable bg = v.getBackground(); if (bg != null) { return bg.getOpacity() == PixelFormat.OPAQUE; } return false; }
Example 11
Source Project: AndroidTint File: EmBackgroundTintHelper.java License: Apache License 2.0 | 5 votes |
/** * * @param view * @param info */ static void applySupportBackgroundTint(View view, TintInfo info) { final Drawable background = view.getBackground(); if (background != null) { if (info != null) { EmTintManager.tintDrawable(background, info, view.getDrawableState()); } } }
Example 12
Source Project: WhereYouGo File: CustomActivity.java License: GNU General Public License v3.0 | 5 votes |
private void unbindDrawables(View view) { if (view == null) return; if (view.getBackground() != null) { view.getBackground().setCallback(null); } if (view instanceof ViewGroup) { for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) { unbindDrawables(((ViewGroup) view).getChildAt(i)); } ((ViewGroup) view).removeAllViews(); } }
Example 13
Source Project: FancyAccordionView File: AnimatorUtils.java License: Apache License 2.0 | 5 votes |
@Override public Integer get(View view) { Drawable background = view.getBackground(); if (background instanceof LayerDrawable && ((LayerDrawable) background).getNumberOfLayers() > 0) { background = ((LayerDrawable) background).getDrawable(0); } return DrawableCompat.getAlpha(background); }
Example 14
Source Project: Android-UtilCode File: ConvertUtils.java License: Apache License 2.0 | 5 votes |
/** * view转Bitmap * * @param view 视图 * @return bitmap */ public static Bitmap view2Bitmap(View view) { if (view == null) return null; Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(ret); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { bgDrawable.draw(canvas); } else { canvas.drawColor(Color.WHITE); } view.draw(canvas); return ret; }
Example 15
Source Project: CodenameOne File: SlidingPaneLayout.java License: GNU General Public License v2.0 | 5 votes |
private static boolean hasOpaqueBackground(View v) { final Drawable bg = v.getBackground(); if (bg != null) { return bg.getOpacity() == PixelFormat.OPAQUE; } return false; }
Example 16
Source Project: fresco File: VitoViewImpl2.java License: MIT License | 4 votes |
@Nullable private static FrescoDrawable2 getDrawable(final View view) { Drawable d = view instanceof ImageView ? ((ImageView) view).getDrawable() : view.getBackground(); return d instanceof FrescoDrawable2 ? (FrescoDrawable2) d : null; }
Example 17
Source Project: AndroidSlidingUpPanel-ScrollView File: SlidingUpPanelLayout.java License: Apache License 2.0 | 4 votes |
private static boolean hasOpaqueBackground(View v) { final Drawable bg = v.getBackground(); return bg != null && bg.getOpacity() == PixelFormat.OPAQUE; }
Example 18
Source Project: PhoneTutorial File: TutorialActivity.java License: Apache License 2.0 | 4 votes |
private void setSmallBackground(View v){ v.setBackgroundResource(R.drawable.background_small_indicator); LayerDrawable layer = (LayerDrawable) v.getBackground(); GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); shape.setColor(colorIndicator); }
Example 19
Source Project: Tangram-Android File: LinearScrollView.java License: MIT License | 4 votes |
private void setViewColor(View view, int color) { if (view.getBackground() instanceof GradientDrawable) { GradientDrawable drawable = (GradientDrawable) view.getBackground().mutate(); drawable.setColor(color); } }
Example 20
Source Project: mobile-manager-tool File: SlidingUpPanelLayout.java License: MIT License | 4 votes |
private static boolean hasOpaqueBackground(View v) { final Drawable bg = v.getBackground(); return bg != null && bg.getOpacity() == PixelFormat.OPAQUE; }