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


Java GradientDrawable.setColor方法代碼示例

本文整理匯總了Java中android.graphics.drawable.GradientDrawable.setColor方法的典型用法代碼示例。如果您正苦於以下問題:Java GradientDrawable.setColor方法的具體用法?Java GradientDrawable.setColor怎麽用?Java GradientDrawable.setColor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.drawable.GradientDrawable的用法示例。


在下文中一共展示了GradientDrawable.setColor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setBackgroundColor

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
@Override
public void setBackgroundColor(int color) {
	backgroundColor = color;
	if (isEnabled()) {
		beforeBackground = backgroundColor;
	}
	try {
		LayerDrawable layer = (LayerDrawable) getBackground();
		// 每個按鈕的框架都是由drawable中的xml文件製定的,xml文件中都有一個item的id叫:shape_bacground
		GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
		/**
		 * 給這個圖片設置背景色,因為圖片的主體是透明的所以可以直接顯示背景色
		 * 效果就是一個透明但有陰影的框架下有了背景色,這樣的方式可以方便的設置不同顏色的按鈕,讓按鈕看起來還是渾然一體
		 */
		shape.setColor(backgroundColor);
		/**
		 * 當重新設定背景色後,要檢查漣漪顏色。如果已經設定了漣漪顏色,那麽就用之前的。如果沒設定就重新生成
		 */
		if (!settedRippleColor) {
			rippleColor = makePressColor(255);
		}
	} catch (Exception ex) {
		// Without bacground
	}
}
 
開發者ID:mityung,項目名稱:XERUNG,代碼行數:26,代碼來源:Button.java

示例2: build

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
public StateListDrawable build(Context ctx) {
    StateListDrawable stateListDrawable = new StateListDrawable();

    GradientDrawable normal = (GradientDrawable) ContextCompat.getDrawable(ctx, R.drawable.action_item_badge);
    GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate();

    normal.setColor(mColor);
    selected.setColor(mColorPressed);

    if (mStroke > -1) {
        normal.setStroke(mStroke, mStrokeColor);
        selected.setStroke(mStroke, mStrokeColor);
    }

    if (mCorners > -1) {
        normal.setCornerRadius(mCorners);
        selected.setCornerRadius(mCorners);
    }

    stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, selected);
    stateListDrawable.addState(StateSet.WILD_CARD, normal);

    return stateListDrawable;
}
 
開發者ID:OmarAliSaid,項目名稱:android-paypal-example,代碼行數:25,代碼來源:BadgeDrawableBuilder.java

示例3: FlatToast

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
public FlatToast(Context context) {
    super(context);
    mContext = context;
    
    //toast text
    textView = new TextView(context);
    textView.setTextColor(Color.WHITE);
    textView.setTextSize(17);
    textView.setPadding(Utils.dip2px(context, 15), Utils.dip2px(context, 8), Utils.dip2px(context, 15), Utils.dip2px(context, 8));
    
    //toast background
    gradientDrawable = new GradientDrawable();
    gradientDrawable.setColor(Color.parseColor("#212121"));
    gradientDrawable.setAlpha(200);
    gradientDrawable.setCornerRadius(Utils.dip2px(context, 10));
}
 
開發者ID:AstinPE,項目名稱:StarchWindow,代碼行數:17,代碼來源:FlatToast.java

示例4: updateSelectedColorPreview

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private void updateSelectedColorPreview() {

        // Create color with selected color values
        int redValue = seekBarRed.getProgress();
        int greenValue = seekBarGreen.getProgress();
        int blueValue = seekBarBlue.getProgress();
        int alpha = seekBarAlpha.getProgress();

        selectedColor = Color.argb(alpha, redValue, greenValue, blueValue);

        GradientDrawable previewBackground = (GradientDrawable) selectedColorPreview.getBackground();
        previewBackground.setColor(selectedColor);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            selectedColorPreview.setBackground(previewBackground);
        }
        else {
            selectedColorPreview.setBackgroundDrawable(previewBackground);
        }
    }
 
開發者ID:Codigami,項目名稱:CFAlertDialog,代碼行數:20,代碼來源:ColorSelectionView.java

示例5: loadHintView

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
 * 加載hintView的容器
 */
private void loadHintView(){
	addView(mHintView);
	mHintView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
	LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
               ViewGroup.LayoutParams.WRAP_CONTENT);
	lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
	((View) mHintView).setLayoutParams(lp);

	GradientDrawable gd = new GradientDrawable();
	gd.setColor(color);
	gd.setAlpha(alpha);
	mHintView.setBackgroundDrawable(gd);

       mHintViewDelegate.initView(mAdapter == null ? 0 : mAdapter.getCount(),
               gravity, (BaseHintView) mHintView);
}
 
開發者ID:yangchong211,項目名稱:YCBanner,代碼行數:20,代碼來源:BannerView.java

示例6: createDrawable

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private GradientDrawable createDrawable(int color, int cornerColor, int cornerSize, int cornerRadius) {
    GradientDrawable out = new GradientDrawable();
    out.setColor(color);
    out.setStroke(cornerSize, cornerColor);
    out.setCornerRadius(cornerRadius);
    return out;
}
 
開發者ID:JMaroz,項目名稱:RoundButton,代碼行數:8,代碼來源:RoundButton.java

示例7: onBindViewHolder

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
 * Called by the RecyclerView to display data at a specified position in the Cursor.
 *
 * @param holder The ViewHolder to bind Cursor data to
 * @param position The position of the data in the Cursor
 */
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {

    // Indices for the _id, description, and priority columns
    int idIndex = mCursor.getColumnIndex(TaskContract.TaskEntry._ID);
    int descriptionIndex = mCursor.getColumnIndex(TaskContract.TaskEntry.COLUMN_DESCRIPTION);
    int priorityIndex = mCursor.getColumnIndex(TaskContract.TaskEntry.COLUMN_PRIORITY);

    mCursor.moveToPosition(position); // get to the right location in the cursor

    // Determine the values of the wanted data
    final int id = mCursor.getInt(idIndex);
    String description = mCursor.getString(descriptionIndex);
    int priority = mCursor.getInt(priorityIndex);

    //Set values
    holder.itemView.setTag(id);
    holder.taskDescriptionView.setText(description);

    // Programmatically set the text and color for the priority TextView
    String priorityString = "" + priority; // converts int to String
    holder.priorityView.setText(priorityString);

    GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
    // Get the appropriate background color based on the priority
    int priorityColor = getPriorityColor(priority);
    priorityCircle.setColor(priorityColor);

}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:36,代碼來源:CustomCursorAdapter.java

示例8: makeNormalDrawable

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
@Override
public Drawable makeNormalDrawable() {
    GradientDrawable dot_normal = new GradientDrawable();
    dot_normal.setColor(normalColor);
    dot_normal.setCornerRadius(SizeUtil.dip2px(getContext(), 4));
    dot_normal.setSize(SizeUtil.dip2px(getContext(), 8), SizeUtil.dip2px(getContext(), 8));
    return dot_normal;
}
 
開發者ID:yangchong211,項目名稱:YCBanner,代碼行數:9,代碼來源:ColorPointHintView.java

示例9: changeBackground

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
public void changeBackground() {
	if (!isInEditMode()) {
		if (value != min) {
			setBackgroundResource(R.drawable.background_checkbox);
			LayerDrawable layer = (LayerDrawable) getBackground();
			GradientDrawable shape = (GradientDrawable) layer
					.findDrawableByLayerId(R.id.shape_bacground);
			shape.setColor(backgroundColor);
		} else {
			setBackgroundResource(R.drawable.background_switch_ball_uncheck);
		}
	}
}
 
開發者ID:mityung,項目名稱:XERUNG,代碼行數:14,代碼來源:Slider.java

示例10: makeFocusDrawable

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
@Override
public Drawable makeFocusDrawable() {
    GradientDrawable dot_focus = new GradientDrawable();
    dot_focus.setColor(focusColor);
    dot_focus.setCornerRadius(SizeUtil.dip2px(getContext(), 4));
    dot_focus.setSize(SizeUtil.dip2px(getContext(), 8), SizeUtil.dip2px(getContext(), 8));
    return dot_focus;
}
 
開發者ID:yangchong211,項目名稱:YCBanner,代碼行數:9,代碼來源:ColorPointHintView.java

示例11: setupBadgeBackgroundColors

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private void setupBadgeBackgroundColors(String BADGE_COLOR) {

        GradientDrawable gd = (GradientDrawable) outer_container.getBackground();
        gd.setColor(Color.parseColor(BADGE_COLOR));

        LayerDrawable layers = (LayerDrawable) bottom_arrow.getBackground();
        RotateDrawable rotate = (RotateDrawable) layers.findDrawableByLayerId(R.id.grad);
        GradientDrawable drawable = (GradientDrawable) rotate.getDrawable();
        drawable.setColor(Color.parseColor(BADGE_COLOR));

    }
 
開發者ID:salRoid,項目名稱:InstaBadge,代碼行數:12,代碼來源:InstaBadgeView.java

示例12: getGradientDrawable

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
public GradientDrawable getGradientDrawable(int strokeWidth,int strokeColor,int fillColor){
    GradientDrawable gd = new GradientDrawable();//創建drawable
    gd.setColor(fillColor);
    gd.setShape(GradientDrawable.OVAL);
    gd.setSize(100, 100);
    gd.setStroke(strokeWidth, strokeColor);
    return gd;
}
 
開發者ID:yaokantv,項目名稱:YKCenterDemo-Android,代碼行數:9,代碼來源:AnimStudy.java

示例13: makeFocusDrawable

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
@Override
   public Drawable makeFocusDrawable()
{
       GradientDrawable dot_focus = new GradientDrawable();
       dot_focus.setColor(focusColor);
       dot_focus.setCornerRadius(dump.v.Util.dip2px(getContext(), 4));
       dot_focus.setSize(dump.v.Util.dip2px(getContext(), 8), dump.v.Util.dip2px(getContext(), 8));
       return dot_focus;
   }
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:10,代碼來源:ColorPointHintView.java

示例14: getBadgeDrawable

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
static GradientDrawable getBadgeDrawable(BadgeItem badgeItem, Context context) {
    GradientDrawable shape = new GradientDrawable();
    shape.setShape(GradientDrawable.RECTANGLE);
    shape.setCornerRadius(context.getResources().getDimensionPixelSize(R.dimen.badge_corner_radius));
    shape.setColor(badgeItem.getBackgroundColor(context));
    shape.setStroke(badgeItem.getBorderWidth(), badgeItem.getBorderColor(context));
    return shape;
}
 
開發者ID:liu-xiao-dong,項目名稱:JD-Test,代碼行數:9,代碼來源:BottomNavigationHelper.java

示例15: createGradientDrawable

import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
public static GradientDrawable createGradientDrawable(int radious, int color) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(color);
    drawable.setCornerRadius((float) radious);
    return drawable;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:7,代碼來源:UIsUtils.java


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