setBackgroundColor ( )源码实例Demo

android.widget.ProgressBar#setBackgroundColor ( )源码实例Demo

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

源代码1 项目: green_android   文件: ProgressBarHandler.java
protected ProgressBar setup(final View view) {
    final ProgressBar progressBar = UI.find(view, R.id.progressBar);
    final int mBackgroundColor = view.getResources().getColor(R.color.green);
    final ColorDrawable[] color1 = {new ColorDrawable(mBackgroundColor),
                                    new ColorDrawable(Color.WHITE)};
    mTransStartLoading = new TransitionDrawable(color1);
    final ColorDrawable[] color2 = {new ColorDrawable(Color.WHITE), new
                                    ColorDrawable(mBackgroundColor)};
    mTransStopLoading = new TransitionDrawable(color2);

    // set progressbar for API < lollipop
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        progressBar.setBackgroundColor(Color.WHITE);
        progressBar.getIndeterminateDrawable().setColorFilter(
            mBackgroundColor, PorterDuff.Mode.SRC_IN);
    }
    progressBar.setIndeterminate(true);
    return progressBar;
}
 
源代码2 项目: FastDownloader   文件: WaitingDialog.java
@SuppressLint("InlinedApi")
private void layoutDesign() {
	setOrientation(LinearLayout.VERTICAL);
	FrameLayout.LayoutParams lParams0 = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
			LayoutParams.WRAP_CONTENT);
	setLayoutParams(lParams0);
	setBackgroundColor(Color.TRANSPARENT);

	ProgressBar progressBar = new ProgressBar(mContext);
	progressBar.setBackgroundColor(Color.TRANSPARENT);
	LayoutParams lParams1 = new LayoutParams(LayoutParams.WRAP_CONTENT,
			LayoutParams.WRAP_CONTENT);
	lParams1.gravity = Gravity.CENTER;
	progressBar.setLayoutParams(lParams1);
	addView(progressBar);
	TextView textView = new TextView(mContext);
	textView.setText(mMessage);
	LayoutParams lParams2 = new LayoutParams(LayoutParams.MATCH_PARENT,
			LayoutParams.WRAP_CONTENT);
	lParams2.gravity = Gravity.CENTER;
	lParams2.width = mScreenWidth;
	textView.setGravity(Gravity.CENTER);
	textView.setLayoutParams(lParams2);
	textView.setBackgroundColor(Color.TRANSPARENT);
	textView.setPadding(mMessagePadding, mMessagePadding, mMessagePadding, mMessagePadding);
	textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mTextSize);
	textView.setTextColor(0xffe5e5e5);
	addView(textView);
}
 
源代码3 项目: MaskEverywhere   文件: LoadingLayoutDemo.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    textView = (TextView)findViewById(R.id.textView);
    mTextViewLoadingMask = new MaskEverywhere(textView);
    ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
    mTextViewLoadingMask.addMaskView(progressBar);
    progressBar.setBackgroundColor(Color.BLACK);
}
 
源代码4 项目: green_android   文件: CircularButton.java
public CircularButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircularButton);

    setLayoutTransition(new LayoutTransition());

    setRadius(getPx(DEFAULT_RADIUS));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setElevation(getPx(DEFAULT_ELEVATION));
    }

    mLinearLayout = new LinearLayout(context);
    mLinearLayout.setOrientation(LinearLayout.VERTICAL);

    // set selectable background
    final TypedValue typedValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
                                             typedValue, true);
    mSelectableItemBackground = typedValue.resourceId;
    mLinearLayout.setBackgroundResource(mSelectableItemBackground);

    // create button
    mButton = new Button(context);
    mButton.setBackgroundColor(Color.TRANSPARENT);
    mButton.setClickable(false);
    mButton.setPadding((int)getPx(15), mButton.getPaddingTop(), (int)getPx(15),
                       mButton.getPaddingBottom());
    final String text = typedArray.getString(R.styleable.CircularButton_text);
    mButton.setText(text);
    mButton.setTextColor(typedArray.getColor(R.styleable.CircularButton_textColor, Color.BLACK));

    // create progressbar
    mProgressBar = new ProgressBar(context);
    mProgressBar.setVisibility(View.GONE);

    // animation transaction
    final LayoutTransition layoutTransition = getLayoutTransition();
    layoutTransition.setDuration(DEFAULT_DURATION);
    layoutTransition.enableTransitionType(LayoutTransition.CHANGING);

    this.setOnClickListener(view -> {
        if (isClickable()) {
            startLoading();
        }
    });

    // set background color animations
    mBackgroundColor = typedArray.getColorStateList(R.styleable.CardView_cardBackgroundColor)
                       .getDefaultColor();
    final ColorDrawable[] color1 = {new ColorDrawable(mBackgroundColor),
                                    new ColorDrawable(Color.WHITE)};
    mTransStartLoading = new TransitionDrawable(color1);
    final ColorDrawable[] color2 = {new ColorDrawable(mSelectableItemBackground), new
                                    ColorDrawable(mBackgroundColor)};
    mTransStopLoading = new TransitionDrawable(color2);

    // set progressbar for API < lollipop
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mProgressBar.setBackgroundColor(Color.WHITE);
        mProgressBar.getIndeterminateDrawable().setColorFilter(
            mBackgroundColor, PorterDuff.Mode.SRC_IN);
    }

    typedArray.recycle();

    // get the width set
    final int[] width = new int[] { android.R.attr.layout_width };
    final TypedArray typedArray1 = context.obtainStyledAttributes(attrs, width);
    mLayoutWidth = typedArray1.getLayoutDimension(0, ViewGroup.LayoutParams.WRAP_CONTENT);
    typedArray1.recycle();

    mLinearLayout.addView(mButton);
    mLinearLayout.addView(mProgressBar);
    addView(mLinearLayout);
}
 
源代码5 项目: GreenBits   文件: CircularButton.java
public CircularButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircularButton);

    setLayoutTransition(new LayoutTransition());

    setRadius(getPx(DEFAULT_RADIUS));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setElevation(getPx(DEFAULT_ELEVATION));
    }

    mLinearLayout = new LinearLayout(context);
    mLinearLayout.setOrientation(LinearLayout.VERTICAL);

    // set selectable background
    final TypedValue typedValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
            typedValue, true);
    mLinearLayout.setBackgroundResource(typedValue.resourceId);

    // create button
    mButton = new Button(context);
    mButton.setBackgroundColor(Color.TRANSPARENT);
    mButton.setClickable(false);
    mButton.setPadding((int)getPx(15), mButton.getPaddingTop(), (int)getPx(15),
            mButton.getPaddingBottom());
    final String text = typedArray.getString(R.styleable.CircularButton_text);
    mButton.setText(text);
    mButton.setTextColor(typedArray.getColor(R.styleable.CircularButton_textColor, Color.BLACK));

    // create progressbar
    mProgressBar = new ProgressBar(context);
    mProgressBar.setVisibility(View.GONE);

    // animation transaction
    final LayoutTransition layoutTransition = getLayoutTransition();
    layoutTransition.setDuration(DEFAULT_DURATION);
    layoutTransition.enableTransitionType(LayoutTransition.CHANGING);

    this.setOnClickListener(view -> {
        if (isClickable()) {
            startLoading();
        }
    });

    // set background color animations
    mBackgroundColor = typedArray.getColorStateList(R.styleable.CardView_cardBackgroundColor)
            .getDefaultColor();
    mLinearLayout.setBackgroundColor(mBackgroundColor);
    final ColorDrawable[] color1 = {new ColorDrawable(mBackgroundColor),
            new ColorDrawable(Color.WHITE)};
    mTransStartLoading = new TransitionDrawable(color1);
    final ColorDrawable[] color2 = {new ColorDrawable(Color.WHITE), new
            ColorDrawable(mBackgroundColor)};
    mTransStopLoading = new TransitionDrawable(color2);

    // set progressbar for API < lollipop
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mProgressBar.setBackgroundColor(Color.WHITE);
        mProgressBar.getIndeterminateDrawable().setColorFilter(
                mBackgroundColor, PorterDuff.Mode.SRC_IN);
    }

    typedArray.recycle();
    mLinearLayout.addView(mButton);
    mLinearLayout.addView(mProgressBar);
    addView(mLinearLayout);
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
	// Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
	
	// Intent
	Intent intent = getIntent();
	Log.i(TAG, "Intent: "+intent.getAction()+" / "+intent.hasExtra(ACTION_HIDE_PROGRESS));
	if (intent.hasExtra(ACTION_HIDE_PROGRESS)) {
		finish();
		this.overridePendingTransition(0, 0);
		
		return;
	}
	
	// Parameters
	Bundle extras = intent.getExtras();
	boolean showOverlay = extras == null || extras.getBoolean(EXTRA_SHOW_OVERLAY, true);
	boolean isFullscreen = extras != null && extras.getBoolean(EXTRA_IS_FULLSCREEN, false);

	// Fullscreen
	if (isFullscreen) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
	}

	// ProgressBar
	ProgressBar bar = new ProgressBar(this, null, android.R.attr.progressBarStyleLarge);
	RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	params.addRule(RelativeLayout.CENTER_IN_PARENT);
	bar.setLayoutParams(params);
	bar.setBackgroundColor(Color.TRANSPARENT);
	
	// Layout
	RelativeLayout layout = new RelativeLayout(this);
	if (showOverlay) layout.setBackgroundColor(Color.parseColor("#aa000000"));
	layout.addView(bar);
	
	// Theme
	setTheme(android.R.style.Theme_Translucent_NoTitleBar);
	setContentView(layout);
}