當前位置: 首頁>>代碼示例>>Java>>正文


Java View.setBackgroundColor方法代碼示例

本文整理匯總了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);
            }
        }


    }
 
開發者ID:ifadai,項目名稱:AndroidThemeChange,代碼行數:23,代碼來源:ThemeUtils.java

示例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);
}
 
開發者ID:kevinwang5658,項目名稱:backstack,代碼行數:26,代碼來源:Helper.java

示例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);
    }
}
 
開發者ID:GuoZhaoHui628,項目名稱:SliderStatusBar,代碼行數:29,代碼來源:StatusBarUtil.java

示例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();
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:33,代碼來源:SnackbarUtils.java

示例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);
    }

}
 
開發者ID:Lingzh0ng,項目名稱:BrotherWeather,代碼行數:25,代碼來源:StatusBarCompat.java

示例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);
}
 
開發者ID:AndroidBoySC,項目名稱:Mybilibili,代碼行數:41,代碼來源:EditPageLand.java

示例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;
    }
}
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:44,代碼來源:SearchAdapter.java

示例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();
        }
    }
}
 
開發者ID:ekumenlabs,項目名稱:tangobot,代碼行數:15,代碼來源:SettingsActivity.java

示例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);
}
 
開發者ID:Horrarndoo,項目名稱:YiZhi,代碼行數:41,代碼來源:EditPagePort.java

示例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;
}
 
開發者ID:yushiwo,項目名稱:StatusBarManager,代碼行數:19,代碼來源:StatusBarUtil.java

示例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));


}
 
開發者ID:androidmaven,項目名稱:pepperColor,代碼行數:28,代碼來源:MainActivity.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:DataBindingActivity.java

示例13: setBackgroundColor

import android.view.View; //導入方法依賴的package包/類
public BaseViewHolder setBackgroundColor(int viewId, int color) {
    View view = getView(viewId);
    view.setBackgroundColor(color);
    return this;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:6,代碼來源:BaseViewHolder.java

示例14: setBackgroundColor

import android.view.View; //導入方法依賴的package包/類
public ViewHolder setBackgroundColor(int viewId, int color) {
    View view = getView(viewId);
    view.setBackgroundColor(color);
    return this;
}
 
開發者ID:fashare2015,項目名稱:MVVM-JueJin,代碼行數:6,代碼來源:ViewHolder.java

示例15: initDummyStatusbar

import android.view.View; //導入方法依賴的package包/類
@Override
protected void initDummyStatusbar(View view) {
    view.setBackgroundColor(getContext().getResources().getColor(R.color.colorPrimary));
}
 
開發者ID:Mindjet,項目名稱:LiteReader,代碼行數:5,代碼來源:DoubanMovieMoreReviewViewModel.java


注:本文中的android.view.View.setBackgroundColor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。