android.view.View#getBackground ( )源码实例Demo

下面列出了android.view.View#getBackground ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Noyze   文件: Utils.java
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);
    }
}
 
源代码2 项目: android-art-res   文件: MainActivity.java
@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);
    }
}
 
源代码3 项目: KlyphMessenger   文件: UserSettingsFragment.java
@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;
}
 
@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;
}
 
源代码5 项目: ucar-weex-core   文件: WXViewUtils.java
/**
 * 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;
}
 
源代码6 项目: Android-UtilCode   文件: ImageUtils.java
/**
 * 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;
}
 
@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;
    }
}
 
源代码8 项目: android-proguards   文件: BackgroundFade.java
@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);
}
 
源代码9 项目: u2020   文件: DebugDrawerLayout.java
private static boolean hasOpaqueBackground(View v) {
  final Drawable bg = v.getBackground();
  if (bg != null) {
    return bg.getOpacity() == PixelFormat.OPAQUE;
  }
  return false;
}
 
源代码10 项目: android-recipes-app   文件: SlidingPaneLayout.java
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;
}
 
源代码11 项目: AndroidTint   文件: EmBackgroundTintHelper.java
/**
 *
 * @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());
        }
    }
}
 
源代码12 项目: WhereYouGo   文件: CustomActivity.java
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();
    }
}
 
源代码13 项目: FancyAccordionView   文件: AnimatorUtils.java
@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);
}
 
源代码14 项目: Android-UtilCode   文件: ConvertUtils.java
/**
 * 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;
}
 
源代码15 项目: CodenameOne   文件: SlidingPaneLayout.java
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    if (bg != null) {
        return bg.getOpacity() == PixelFormat.OPAQUE;
    }
    return false;
}
 
源代码16 项目: fresco   文件: VitoViewImpl2.java
@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;
}
 
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}
 
源代码18 项目: PhoneTutorial   文件: TutorialActivity.java
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);
}
 
源代码19 项目: Tangram-Android   文件: LinearScrollView.java
private void setViewColor(View view, int color) {
    if (view.getBackground() instanceof GradientDrawable) {
        GradientDrawable drawable = (GradientDrawable) view.getBackground().mutate();
        drawable.setColor(color);
    }
}
 
源代码20 项目: mobile-manager-tool   文件: SlidingUpPanelLayout.java
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}
 
 方法所在类
 同类方法