本文整理汇总了Java中android.view.View.setBackgroundColor方法的典型用法代码示例。如果您正苦于以下问题:Java View.setBackgroundColor方法的具体用法?Java View.setBackgroundColor怎么用?Java View.setBackgroundColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.setBackgroundColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setWindowStatusBarColor
import android.view.View; //导入方法依赖的package包/类
/**
* 当前页面设置状态栏颜色
*
* */
public static void setWindowStatusBarColor(Activity activity, int color){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
View view=contentView.getChildAt(1);
view.setBackgroundColor(color);
} else {
Window window=activity.getWindow();
if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.LOLLIPOP){
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// 状态栏
window.setStatusBarColor(color);
// 底部导航栏
window.setNavigationBarColor(color);
}
}
}
示例2: disable
import android.view.View; //导入方法依赖的package包/类
/**
* Helper function to disable a ViewGroup and all it's children. This draws a new view with z-ordering of integer max
* that consumes all touch events.
* @param viewGroup
*/
public static void disable(ViewGroup viewGroup){
View view = new View(viewGroup.getContext());
viewGroup.addView(view);
view.setTag(DISABLE);
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = MATCH_PARENT;
params.width = MATCH_PARENT;
view.setLayoutParams(params);
view.setClickable(true);
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.setBackgroundColor(Color.TRANSPARENT);
if (Build.VERSION.SDK_INT >= 21) {
view.setTranslationZ(Integer.MAX_VALUE);
}
viewGroup.bringChildToFront(view);
}
示例3: setColor
import android.view.View; //导入方法依赖的package包/类
/**
* 设置状态栏颜色
*
* @param activity 需要设置的activity
* @param color 状态栏颜色值
* @param statusBarAlpha 状态栏透明度
*/
public static void setColor(Activity activity, @ColorInt int color, int statusBarAlpha) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
if (fakeStatusBarView != null) {
if (fakeStatusBarView.getVisibility() == View.GONE) {
fakeStatusBarView.setVisibility(View.VISIBLE);
}
fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
} else {
decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
}
setRootView(activity);
}
}
示例4: showSnackbar
import android.view.View; //导入方法依赖的package包/类
/**
* 设置snackbar文字和背景颜色
*
* @param parent 父视图(CoordinatorLayout或者DecorView)
* @param text 文本
* @param duration 显示时长
* @param textColor 文本颜色
* @param bgColor 背景色
* @param actionText 事件文本
* @param actionTextColor 事件文本颜色
* @param listener 监听器
*/
private static void showSnackbar(View parent, CharSequence text, int duration, @ColorInt int textColor, @ColorInt int bgColor,
CharSequence actionText, int actionTextColor, View.OnClickListener listener) {
switch (duration) {
default:
case Snackbar.LENGTH_SHORT:
case Snackbar.LENGTH_LONG:
snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, text, duration));
break;
case Snackbar.LENGTH_INDEFINITE:
snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, text, Snackbar.LENGTH_INDEFINITE).setDuration(duration));
}
View view = snackbarWeakReference.get().getView();
((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(textColor);
view.setBackgroundColor(bgColor);
if (actionText != null && actionText.length() > 0 && listener != null) {
snackbarWeakReference.get().setActionTextColor(actionTextColor);
snackbarWeakReference.get().setAction(actionText, listener);
}
snackbarWeakReference.get().show();
}
示例5: compat
import android.view.View; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void compat(Activity activity, int statusColor) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (statusColor != INVALID_VAL) {
activity.getWindow().setStatusBarColor(statusColor);
}
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
int color = COLOR_DEFAULT;
ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
if (statusColor != INVALID_VAL) {
color = statusColor;
}
View statusBarView = new View(activity);
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
getStatusHeight(activity));
statusBarView.setBackgroundColor(color);
contentView.addView(statusBarView, lp);
}
}
示例6: initBottom
import android.view.View; //导入方法依赖的package包/类
private void initBottom(LinearLayout llBottom, float ratio) {
LinearLayout llAt = new LinearLayout(activity);
llAt.setPadding(0, 0, 0, 5);
llAt.setBackgroundColor(0xffffffff);
int bottomHeight = (int) (DESIGN_BOTTOM_HEIGHT * ratio);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, bottomHeight);
llBottom.addView(llAt, lp);
tvAt = new TextView(activity);
tvAt.setTextColor(0xff3b3b3b);
tvAt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
tvAt.setGravity(Gravity.BOTTOM);
tvAt.setText("@");
int padding = (int) (DESIGN_LEFT_PADDING * ratio);
tvAt.setPadding(padding, 0, padding, 0);
lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
llAt.addView(tvAt, lp);
tvAt.setOnClickListener(this);
if (isShowAtUserLayout(platform.getName())) {
tvAt.setVisibility(View.VISIBLE);
} else {
tvAt.setVisibility(View.INVISIBLE);
}
tvTextCouter = new TextView(activity);
tvTextCouter.setTextColor(0xff3b3b3b);
tvTextCouter.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
tvTextCouter.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
onTextChanged(etContent.getText(), 0, 0, 0);
tvTextCouter.setPadding(padding, 0, padding, 0);
lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
lp.weight = 1;
llAt.addView(tvTextCouter, lp);
View v = new View(activity);
v.setBackgroundColor(0xffcccccc);
int px1 = ratio > 1 ? ((int) ratio) : 1;
lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, px1);
llBottom.addView(v, lp);
}
示例7: ViewHolder
import android.view.View; //导入方法依赖的package包/类
public ViewHolder(@NonNull View itemView, int itemViewType) {
super(itemView);
itemView.setOnLongClickListener(null);
if (itemViewType != HEADER) {
itemView.setBackgroundColor(ATHUtil.resolveColor(activity, R.attr.cardBackgroundColor));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
itemView.setElevation(activity.getResources().getDimensionPixelSize(R.dimen.card_elevation));
}
if (shortSeparator != null) {
shortSeparator.setVisibility(View.GONE);
}
}
if (menu != null) {
if (itemViewType == SONG) {
menu.setVisibility(View.VISIBLE);
menu.setOnClickListener(new SongMenuHelper.OnClickSongMenu(activity) {
@Override
public Song getSong() {
return (Song) dataSet.get(getAdapterPosition());
}
});
} else {
menu.setVisibility(View.GONE);
}
}
switch (itemViewType) {
case ALBUM:
setImageTransitionName(activity.getString(R.string.transition_album_art));
break;
case ARTIST:
setImageTransitionName(activity.getString(R.string.transition_artist_image));
break;
default:
View container = itemView.findViewById(R.id.image_container);
if (container != null) {
container.setVisibility(View.GONE);
}
break;
}
}
示例8: onSharedPreferenceChanged
import android.view.View; //导入方法依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key == getString(R.string.pref_master_is_local_key) ||
key == getString(R.string.pref_master_uri_key)) {
if (settingsWereAppliedThisSession() && mSettingsPreferenceFragment.getView() != null) {
Snackbar snackbar = Snackbar.make(mSettingsPreferenceFragment.getView(),
getString(R.string.snackbar_text_restart), Snackbar.LENGTH_INDEFINITE);
View snackBarView = snackbar.getView();
snackBarView.setBackgroundColor(getResources().getColor(android.R.color.holo_orange_dark));
snackbar.show();
}
}
}
示例9: initBottom
import android.view.View; //导入方法依赖的package包/类
private void initBottom(LinearLayout llBottom, float ratio) {
LinearLayout llAt = new LinearLayout(activity);
llAt.setPadding(0, 0, 0, 5);
llAt.setBackgroundColor(0xffffffff);
int bottomHeight = (int) (DESIGN_BOTTOM_HEIGHT * ratio);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, bottomHeight);
llBottom.addView(llAt, lp);
tvAt = new TextView(activity);
tvAt.setTextColor(0xff3b3b3b);
tvAt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
tvAt.setGravity(Gravity.BOTTOM);
tvAt.setText("@");
int padding = (int) (DESIGN_LEFT_PADDING * ratio);
tvAt.setPadding(padding, 0, padding, 0);
lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
llAt.addView(tvAt, lp);
tvAt.setOnClickListener(this);
if (isShowAtUserLayout(platform.getName())) {
tvAt.setVisibility(View.VISIBLE);
} else {
tvAt.setVisibility(View.INVISIBLE);
}
tvTextCouter = new TextView(activity);
tvTextCouter.setTextColor(0xff3b3b3b);
tvTextCouter.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
tvTextCouter.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
onTextChanged(etContent.getText(), 0, 0, 0);
tvTextCouter.setPadding(padding, 0, padding, 0);
lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
lp.weight = 1;
llAt.addView(tvTextCouter, lp);
View v = new View(activity);
v.setBackgroundColor(0xffcccccc);
int px1 = ratio > 1 ? ((int) ratio) : 1;
lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, px1);
llBottom.addView(v, lp);
}
示例10: createStatusBarView
import android.view.View; //导入方法依赖的package包/类
/**
* 生成一个和状态栏大小相同的半透明矩形条
*
* @param activity 需要设置的activity
* @param color 状态栏颜色值
* @param alpha 透明值
* @return 状态栏矩形条
*/
private static View createStatusBarView(Activity activity, @ColorInt int color, int alpha) {
// 绘制一个和状态栏一样高的矩形
View statusBarView = new View(activity);
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
statusBarView.setLayoutParams(params);
statusBarView.setBackgroundColor(calculateStatusColor(color, alpha));
statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID);
return statusBarView;
}
示例11: onCreate
import android.view.View; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View view1 = findViewById(R.id.view1);
View view2 = findViewById(R.id.view2);
View view3 = findViewById(R.id.view3);
//Using PEPPER SINGLE COLOR IN TWO METHODS (READ DOCUMENTATIONS github.com/tobilvr/peppercolor).
//ONE OF THE METHODS.
view1.setBackgroundColor(new PepperSingleColor.Builder().setColor(PepperColors.PINK100).setTransparency(40).build());
//Using PEPPER GRADIENT
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view2.setBackground(
new PepperGradient().start(PepperColors.ORANGE100
,PepperColors.GREEN400,
GradientDrawable.Orientation.TR_BL
,GradientDrawable.LINEAR_GRADIENT
));
}
//Using PEPPER BLEND
view3.setBackgroundColor(new PepperBlend().start(PepperColors.GREEN200,PepperColors.AMBER600, 0.8f));
}
示例12: getContainer
import android.view.View; //导入方法依赖的package包/类
private View getContainer(View rootView) {
rootView.setBackgroundColor(getResources().getColor(R.color.alpha_white));
View container = getLayoutInflater().inflate(R.layout.activity_base, null, false);
SwipeBackLayout swipeBackLayout = (SwipeBackLayout) container.findViewById(R.id.swipeBackLayout);
View ivShadow = container.findViewById(R.id.iv_shadow);
swipeBackLayout.addView(rootView);
swipeBackLayout.setOnScroll((fs) -> ivShadow.setAlpha(1 - fs));
return container;
}
示例13: setBackgroundColor
import android.view.View; //导入方法依赖的package包/类
public BaseViewHolder setBackgroundColor(int viewId, int color) {
View view = getView(viewId);
view.setBackgroundColor(color);
return this;
}
示例14: setBackgroundColor
import android.view.View; //导入方法依赖的package包/类
public ViewHolder setBackgroundColor(int viewId, int color) {
View view = getView(viewId);
view.setBackgroundColor(color);
return this;
}
示例15: initDummyStatusbar
import android.view.View; //导入方法依赖的package包/类
@Override
protected void initDummyStatusbar(View view) {
view.setBackgroundColor(getContext().getResources().getColor(R.color.colorPrimary));
}