@OnClick(R.id.more) public void more(View view) { View popupView = mInflater.inflate(R.layout.popup_reply, null); popupView.findViewById(R.id.favour).setOnClickListener(this); popupView.findViewById(R.id.comment).setOnClickListener(this); window = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); window.setOutsideTouchable(true); window.setFocusable(true); window.setAnimationStyle(R.style.popup_more_anim); window.setBackgroundDrawable(new ColorDrawable(Color.BLACK)); popupView.measure(0, 0); int xoff = -popupView.getMeasuredWidth(); int yoff = -(popupView.getMeasuredHeight() + view.getHeight()) / 2; window.showAsDropDown(view, xoff, yoff); }
@Test public void shouldSetBackgroundColor() { int red = 0xffff0000; view.setBackgroundColor(red); ColorDrawable background = (ColorDrawable) view.getBackground(); assertThat(background.getColor()).isEqualTo(red); }
public static void tintViewBackground(View view, TintInfo tint) { Drawable background; if (view == null || (background = view.getBackground()) == null) return; if (tint.mHasTintList || tint.mHasTintMode) { background.mutate(); if (background instanceof ColorDrawable) { ((ColorDrawable) background).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList.getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor()))); } else { background.setColorFilter(createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null, tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState())); } } else { background.clearColorFilter(); } if (Build.VERSION.SDK_INT <= 23) { // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter // has changed, so we need to force an invalidation background.invalidateSelf(); } }
@SuppressLint("NewApi") @Override public void setValue(ForegroundFrame layout, int value) { if (layout.getForeground() instanceof ColorDrawable) { ((ColorDrawable) layout.getForeground().mutate()).setColor(value); } else { layout.setForeground(new ColorDrawable(value)); } }
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mSearchView = (FloatingSearchView) view.findViewById(R.id.floating_search_view); mHeaderView = view.findViewById(R.id.header_view); mDimSearchViewBackground = view.findViewById(R.id.dim_background); mDimDrawable = new ColorDrawable(Color.BLACK); mDimDrawable.setAlpha(0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mDimSearchViewBackground.setBackground(mDimDrawable); } else { mDimSearchViewBackground.setBackgroundDrawable(mDimDrawable); } setupFloatingSearch(); setupDrawer(); }
@Test public void testProvidesCurrentPlaceholderToAnimationIfPresent() { Drawable placeholder = new ColorDrawable(Color.BLACK); view.setImageDrawable(placeholder); @SuppressWarnings("unchecked") Transition<Drawable> animation = mock(Transition.class); target.onResourceReady(new ColorDrawable(Color.GREEN), animation); ArgumentCaptor<Drawable> drawableCaptor = ArgumentCaptor.forClass(Drawable.class); verify(animation).transition(drawableCaptor.capture(), eq(target)); assertThat(((ColorDrawable) drawableCaptor.getValue()).getColor()).isEqualTo(Color.GREEN); }
private void setAccountViews(final List<AccountBean> accounts, final View view, final int index) { ImageView image = (ImageView) view.findViewById(R.id.imgAccount); ImageView cover = (ImageView) view.findViewById(R.id.imgCover); ColorDrawable grayDrawable = new ColorDrawable(Color.parseColor("#29000000")); cover.setImageDrawable(grayDrawable); view.setVisibility(accounts.size() >= index + 1 ? View.VISIBLE : View.GONE); if (view.getVisibility() == View.VISIBLE) { BitmapLoader.getInstance().display(menuFragment, accounts.get(index).getUser().getAvatar_large(), image, ImageConfigUtils.getLargePhotoConfig()); view.setTag(accounts.get(index)); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { UMengUtil.onEvent(menuFragment.getActivity(), "menuheader_account_change"); AccountBean account = (AccountBean) v.getTag(); changeAccount(account, v); } }); } }
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { //noinspection ConstantConditions getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); View view = inflater.inflate(R.layout.dialog_settings, container, false); swSolidRow = view.findViewById(R.id.swSolidRow); swFixedHeaders = view.findViewById(R.id.swFixedHeaders); swRtlDirection = view.findViewById(R.id.swRtlDirection); swDragAndDropEnabled = view.findViewById(R.id.swDragAndDropEnabled); return view; }
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { //noinspection ConstantConditions getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); View view = inflater.inflate(R.layout.dialog_edit_item, container, false); mTilValue = view.findViewById(R.id.tilValue); mEtValue = view.findViewById(R.id.etValue); mTvDelete = view.findViewById(R.id.tvDelete); mTvAdd = view.findViewById(R.id.tvAdd); mTvDelete.setOnClickListener(this); mTvAdd.setOnClickListener(this); view.findViewById(R.id.bPositive).setOnClickListener(this); view.findViewById(R.id.bNegative).setOnClickListener(this); return view; }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) convertView = View.inflate(getActivity(), R.layout.item_mdcolors, null); if (!colorMap.containsKey(String.valueOf(position))) colorMap.put(String.valueOf(position), new ColorDrawable(getResources().getColor(ThemeUtils.themeColorArr[position][0]))); CircleImageView imgColor = (CircleImageView) convertView.findViewById(R.id.imgColor); ColorDrawable colorDrawable = colorMap.get(String.valueOf(position)); imgColor.setImageDrawable(colorDrawable); View imgSelected = convertView.findViewById(R.id.imgSelected); imgSelected.setVisibility(AppSettings.getThemeColor() == position ? View.VISIBLE : View.GONE); return convertView; }
public PopupMenu(Context context) { super(android.view.View.inflate(context, R.layout.carbon_popupmenu, null)); getContentView().setLayoutParams(new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); recycler = getContentView().findViewById(R.id.recycler); recycler.setLayoutManager(new LinearLayoutManager(context)); recycler.setOnKeyListener((v, keyCode, event) -> { if (event.getAction() == KeyEvent.ACTION_UP && (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_BACK)) { dismiss(); return true; } return false; }); setBackgroundDrawable(new ColorDrawable(context.getResources().getColor(android.R.color.transparent))); setTouchable(true); setFocusable(true); setOutsideTouchable(true); setAnimationStyle(0); }
public void show() { View anchor = context.getWindow().getDecorView().getRootView(); setContentView(new DebugLayout(context, anchor)); getContentView().setLayoutParams(new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); setBackgroundDrawable(new ColorDrawable(context.getResources().getColor(android.R.color.transparent))); setTouchable(false); setFocusable(false); setOutsideTouchable(false); setAnimationStyle(0); super.showAtLocation(anchor, Gravity.START | Gravity.TOP, 0, 0); update(anchor.getWidth(), anchor.getHeight()); anchor.getViewTreeObserver().addOnPreDrawListener(listener); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); view = new ImageView(RuntimeEnvironment.application); target = new TestTarget(view); drawable = new ColorDrawable(Color.RED); }
@Before public void setup() { mContext1 = RuntimeEnvironment.application; mContext2 = new ContextWrapper(RuntimeEnvironment.application); mActivityController = Robolectric.buildActivity(Activity.class).create(); mActivity = mActivityController.get(); mMountContent = new ColorDrawable(Color.RED); mNewMountContent = new View(mContext1); }
@Deprecated public static void setupActionBarColor(@NonNull AppCompatActivity activity, int color) { Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar); if (toolbar == null) return; activity.setSupportActionBar(toolbar); ActionBar actionBar = activity.getSupportActionBar(); if (actionBar == null) return; actionBar.setDisplayHomeAsUpEnabled(true); ColorDrawable drawable = new ColorDrawable(color); actionBar.setBackgroundDrawable(drawable); if (SDK_INT >= LOLLIPOP) { int darkerColor = ColorUtils.mixColors(color, Color.BLACK, 0.75f); activity.getWindow().setStatusBarColor(darkerColor); toolbar.setElevation(InterfaceUtils.dpToPixels(activity, 2)); View view = activity.findViewById(R.id.toolbarShadow); if (view != null) view.setVisibility(View.GONE); view = activity.findViewById(R.id.headerShadow); if (view != null) view.setVisibility(View.GONE); } }
assertThat(mHost.getInvalidationRect()).isNull(); Drawable d1 = new ColorDrawable(); d1.setBounds(0, 0, 1, 1); assertThat(mHost.getInvalidationRect()).isEqualTo(d1.getBounds()); Drawable d2 = new ColorDrawable(); d2.setBounds(0, 0, 2, 2); assertThat(mHost.getInvalidationRect()).isEqualTo(d2.getBounds()); View v1 = new View(mContext.getAndroidContext()); Rect v1Bounds = new Rect(0, 0, 10, 10); v1.measure( makeMeasureSpec(v1Bounds.width(), EXACTLY), makeMeasureSpec(v1Bounds.height(), EXACTLY)); v1.layout(v1Bounds.left, v1Bounds.top, v1Bounds.right, v1Bounds.bottom);
public EditTextMenu(Context context) { super(LayoutInflater.from(context).inflate(R.layout.carbon_editormenu, null, false)); getContentView().setLayoutParams(new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); setBackgroundDrawable(new ColorDrawable(context.getResources().getColor(android.R.color.transparent))); setTouchable(true); setFocusable(true); setOutsideTouchable(true); setAnimationStyle(0); setClippingEnabled(false); }
private void initBackground() { mBackground = new ColorDrawable(Color.BLACK); MyUtils.getRootView(this).setBackgroundDrawable(mBackground); }
/************************************拖拽滑动****************************************/ @Override public void onItemSelected() { if (bgDrawable == null) { bgDrawable = itemView.getBackground(); } if (dragDrawable == null) { dragDrawable = new ColorDrawable(Color.LTGRAY); } itemView.setBackgroundDrawable(dragDrawable); }
public static void tintViewDrawable(View view, Drawable drawable, TintInfo tint) { if (view == null || drawable == null) return; if (tint.mHasTintList || tint.mHasTintMode) { drawable.mutate(); if (drawable instanceof ColorDrawable) { ((ColorDrawable) drawable).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList.getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor()))); } else { drawable.setColorFilter(createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null, tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState())); } } else { drawable.clearColorFilter(); } if (Build.VERSION.SDK_INT <= 23) { // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter // has changed, so we need to force an invalidation drawable.invalidateSelf(); } }