Java Code Examples for android.widget.LinearLayout.setBackground()

The following are Jave code examples for showing how to use setBackground() of the android.widget.LinearLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ePills   File: AddPillSetTime.java   View Source Code Vote up 6 votes
/**
 * This view disables tapping on the day objects and on the endDate label. It also
 * colors them following the material design specification.
  */
private void disableDays() {
    double opacity = 0.26; //Following the material specification, disabled buttons have opacity 26%
    for (int i = 0; i < weekdaysSelection.length; i++) {
        LinearLayout day = getDayLayout(i);
        day.setOnClickListener(null);
        endDateTextView.setOnClickListener(null);
        endDateTextView.setAlpha( (float) (opacity * 255 /100));
        int colorBlack = ContextCompat.getColor(getBaseContext(), R.color.black);
        if (day.getBackground()== null) {
            Drawable bg = ContextCompat.getDrawable(getBaseContext(), R.drawable.circle_step);
            bg.setColorFilter(new PorterDuffColorFilter(colorBlack, PorterDuff.Mode.SRC_IN));
            bg.setAlpha((int) (opacity * 255));
            day.setBackground(bg);
        } else {
            day.getBackground().setColorFilter(new PorterDuffColorFilter(colorBlack, PorterDuff.Mode.SRC_IN));
            day.getBackground().setAlpha((int) (opacity * 255));
        }
    }
}
 
Example 2
Project: BBSSDK-for-Android   File: Theme0StyleModifier.java   View Source Code Vote up 5 votes
public static void modifyUniformBlueStyle(BasePageWithTitle basepage) {
	if (basepage == null) {
		return;
	}
	Context context = basepage.getContext();
	TitleBar titlebar = basepage.getTitleBar();
	LinearLayout mainlayout = basepage.getMainLayout();
	if (titlebar == null) {
		throw new IllegalArgumentException("titleBar is not initialized!");
	} else {
		titlebar.setBackgroundColor(Color.TRANSPARENT);
		titlebar.getTitleTextView().setTextColor(context.getResources().getColor(basepage.getColorId("bbs_white")));
		setTextSize(titlebar.getTitleTextView(), "bbs_theme0_title_txt_size");
	}

	if (mainlayout == null) {
		throw new IllegalArgumentException("mainLayout is not initialized!");
	} else {
		Drawable drawable = context.getResources().getDrawable(basepage.getDrawableId("bbs_theme0_bg_userpage"));
		if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
			mainlayout.setBackgroundDrawable(drawable);
		} else {
			mainlayout.setBackground(drawable);
		}
	}
	basepage.setStatusBarColor(context.getResources().getColor(basepage.getColorId("bbs_theme0_statusbar_blue")));
}
 
Example 3
Project: BBSSDK-for-Android   File: Theme0StyleModifier.java   View Source Code Vote up 5 votes
public static void modifyUniformWhiteStyle(BasePageWithTitle basepage) {
	if (basepage == null) {
		return;
	}
	Context context = basepage.getContext();
	TitleBar titlebar = basepage.getTitleBar();
	LinearLayout mainlayout = basepage.getMainLayout();
	if (titlebar == null) {
		throw new IllegalArgumentException("titleBar is not initialized!");
	} else {
		titlebar.setBackgroundColor(Color.TRANSPARENT);
		if(titlebar.getTitleTextView() != null) {
			titlebar.getTitleTextView().setTextColor(context.getResources().getColor(basepage.getColorId("bbs_theme0_pagetext")));
			setTextSize(titlebar.getTitleTextView(), "bbs_theme0_title_txt_size");
		}
	}

	if (mainlayout == null) {
		throw new IllegalArgumentException("mainLayout is not initialized!");
	} else {
		ColorDrawable drawable = new ColorDrawable(context.getResources().getColor(basepage.getColorId("bbs_white")));
		if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
			mainlayout.setBackgroundDrawable(drawable);
		} else {
			mainlayout.setBackground(drawable);
		}
	}
	basepage.setStatusBarColor(BBSViewBuilder.getInstance().getStatusBarColor(context));
}
 
Example 4
Project: BBSSDK-for-Android   File: Theme1StyleModifier.java   View Source Code Vote up 5 votes
public static void modifyUniformWhiteStyle(BasePageWithTitle basepage) {
	if (basepage == null) {
		return;
	}
	Context context = basepage.getContext();
	TitleBar titlebar = basepage.getTitleBar();
	LinearLayout mainlayout = basepage.getMainLayout();
	if (titlebar == null) {
		throw new IllegalArgumentException("titleBar is not initialized!");
	} else {
		titlebar.setBackgroundColor(Color.TRANSPARENT);
		if(titlebar.getTitleTextView() != null) {
			titlebar.getTitleTextView().setTextColor(context.getResources().getColor(basepage.getColorId("bbs_theme1_pagetext")));
			setTextSize(titlebar.getTitleTextView(), "bbs_theme1_title_txt_size");
		}
	}

	if (mainlayout == null) {
		throw new IllegalArgumentException("mainLayout is not initialized!");
	} else {
		ColorDrawable drawable = new ColorDrawable(context.getResources().getColor(basepage.getColorId("bbs_white")));
		if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
			mainlayout.setBackgroundDrawable(drawable);
		} else {
			mainlayout.setBackground(drawable);
		}
	}
	basepage.setStatusBarColor(context.getResources().getColor(basepage.getColorId("bbs_theme1_statusbar")));
}
 
Example 5
Project: MarsBootProject   File: MToast.java   View Source Code Vote up 5 votes
@SuppressLint("InflateParams")
private static View inflateToastLayout(CharSequence message, int type) {
    LinearLayout layout = new LinearLayout(appContext);
    LayoutInflater inflater = (LayoutInflater) appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.custom_toast_container, null);
    layout.addView(view);

    LinearLayout customToastContainer = (LinearLayout) layout.findViewById(R.id.custom_toast_container);
    ImageView icon = (ImageView) layout.findViewById(R.id.icon);
    TextView text = (TextView) layout.findViewById(R.id.text);

    switch (type) {
        case TYPE_SUCCESS:
            icon.setImageDrawable(ContextCompat.getDrawable(appContext, R.drawable.ic_check_circle_white_24dp));
            customToastContainer.setBackground(ContextCompat.getDrawable(appContext, R.drawable.custom_toast_success_background));
            break;
        case TYPE_WARNING:
            icon.setImageDrawable(ContextCompat.getDrawable(appContext, R.drawable.ic_warning_white_24dp));
            customToastContainer.setBackground(ContextCompat.getDrawable(appContext, R.drawable.custom_toast_warn_background));
            break;
        case TYPE_ERROR:
            icon.setImageDrawable(ContextCompat.getDrawable(appContext, R.drawable.ic_error_white_24dp));
            customToastContainer.setBackground(ContextCompat.getDrawable(appContext, R.drawable.custom_toast_error_background));
            break;
        default:
            icon.setImageDrawable(ContextCompat.getDrawable(appContext, R.drawable.ic_info_white_24dp));
            customToastContainer.setBackground(ContextCompat.getDrawable(appContext, R.drawable.custom_toast_info_background));
            break;
    }

    text.setText(message);

    return layout;
}
 
Example 6
Project: ePills   File: AddPillSetTime.java   View Source Code Vote up 5 votes
/**
 * Selects the Day on position 'index'.
 * @param index
 * @param dayLayout
 * @param check: True if checkDays() should be called.
 */
private void activateDay(int index, LinearLayout dayLayout, boolean check) {
    weekdaysSelection[index] = true;

    dayLayout.setTag(true);
    Drawable bg = ContextCompat.getDrawable(getBaseContext(), R.drawable.circle_step);
    int colorPrimary = ContextCompat.getColor(getBaseContext(), R.color.accent);
    bg.setColorFilter(new PorterDuffColorFilter(colorPrimary, PorterDuff.Mode.SRC_IN));
    dayLayout.setBackground(bg);
    TextView day = (TextView) dayLayout.findViewById(R.id.day);
    day.setTextColor(ContextCompat.getColor(getBaseContext(),R.color.md_white_1000));
    if(check) {
        checkDays();
    }
}
 
Example 7
Project: CommonLibrary   File: MToast.java   View Source Code Vote up 5 votes
@SuppressLint("InflateParams")
private static View inflateToastLayout(CharSequence message, int type) {
    LinearLayout layout = new LinearLayout(appContext);
    LayoutInflater inflater = (LayoutInflater) appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.custom_toast_container, null);
    layout.addView(view);

    LinearLayout customToastContainer = (LinearLayout) layout.findViewById(R.id.custom_toast_container);
    ImageView icon = (ImageView) layout.findViewById(R.id.icon);
    TextView text = (TextView) layout.findViewById(R.id.text);

    switch (type) {
        case TYPE_SUCCESS:
            icon.setImageDrawable(ContextCompat.getDrawable(appContext, R.drawable.ic_check_circle_white_24dp));
            customToastContainer.setBackground(ContextCompat.getDrawable(appContext, R.drawable.custom_toast_success_background));
            break;
        case TYPE_WARNING:
            icon.setImageDrawable(ContextCompat.getDrawable(appContext, R.drawable.ic_warning_white_24dp));
            customToastContainer.setBackground(ContextCompat.getDrawable(appContext, R.drawable.custom_toast_warn_background));
            break;
        case TYPE_ERROR:
            icon.setImageDrawable(ContextCompat.getDrawable(appContext, R.drawable.ic_error_white_24dp));
            customToastContainer.setBackground(ContextCompat.getDrawable(appContext, R.drawable.custom_toast_error_background));
            break;
        default:
            icon.setImageDrawable(ContextCompat.getDrawable(appContext, R.drawable.ic_info_white_24dp));
            customToastContainer.setBackground(ContextCompat.getDrawable(appContext, R.drawable.custom_toast_info_background));
            break;
    }

    text.setText(message);

    return layout;
}
 
Example 8
Project: pius1   File: MaterialDialog.java   View Source Code Vote up 4 votes
public void setBackground(Drawable drawable)
{
           LinearLayout linearLayout = (LinearLayout) mAlertDialogWindow.findViewById(
	R.id.material_background);
           linearLayout.setBackground(drawable);
       }
 
Example 9
Project: andcoachmark   File: OkBelowDescriptionButtonRenderer.java   View Source Code Vote up 4 votes
@Override
public View render(final CoachmarkViewLayout layout) {

    if (inflated == null) {
        LayoutInflater inflater = (LayoutInflater) layout.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflated = inflater.inflate(R.layout.ok_below_description_button_view, null);
        layout.addView(inflated);
    }


    TextView mTxtOkBtn = (TextView) inflated.findViewById(R.id.txt_ok_btn);
    LinearLayout mGroupOk = (LinearLayout) inflated.findViewById(R.id.group_ok);

    mTxtOkBtn.setText(mOkText);
    mGroupOk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mListener == null || mListener.onClicked()) {
                layout.dismiss();
            }
        }
    });

    if (mBorder != 0) {
        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setStroke(mBorder, mColor != null ? mColor : ContextCompat.getColor(layout.getContext(),R.color.default_border_color));
        mGroupOk.setBackground(gradientDrawable);

    }

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    inflated.setLayoutParams(params);


    inflated.post(new Runnable() {
        @Override
        public void run() {
            RectF descriptionRectangle = layout.calcDescriptionRect();
            inflated.setX(descriptionRectangle.centerX() - ((float) inflated.getWidth() / 2));
            inflated.setY(descriptionRectangle.bottom + inflated.getContext().getResources().getDimension(R.dimen.button_padding));
            inflated.setVisibility(View.VISIBLE);
        }
    });

    return inflated;


}
 
Example 10
Project: microbit   File: ProjectAdapter.java   View Source Code Vote up 4 votes
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    Project project = mProjects.get(position);
    if(convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(MBApp.getApp());
        convertView = inflater.inflate(R.layout.project_items, null);
    }

    Button appNameButton = (Button) convertView.findViewById(R.id.appNameButton);
    appNameButton.setTypeface(MBApp.getApp().getRobotoTypeface());

    ExtendedEditText appNameEdit = (ExtendedEditText) convertView.findViewById(R.id.appNameEdit);
    appNameEdit.setTypeface(MBApp.getApp().getRobotoTypeface());

    LinearLayout actionBarLayout = (LinearLayout) convertView.findViewById(R.id.actionBarForProgram);
    if(actionBarLayout != null) {
        if(project.actionBarExpanded) {
            actionBarLayout.setVisibility(View.VISIBLE);
            appNameButton.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(MBApp.getApp()
                    , R.drawable.ic_arrow_down), null);
        } else {
            actionBarLayout.setVisibility(View.GONE);
            appNameButton.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(MBApp.getApp()
                    , R.drawable.ic_arrow_left), null);
        }
    }

    appNameButton.setText(project.name);
    appNameButton.setTag(R.id.positionId, position);
    appNameButton.setTag(R.id.textEdit, appNameEdit);
    appNameButton.setOnClickListener(appNameClickListener);
    appNameButton.setOnLongClickListener(appNameLongClickListener);

    appNameEdit.setTag(R.id.positionId, position);
    appNameEdit.setTag(R.id.editbutton, appNameButton);
    appNameEdit.setOnEditorActionListener(editorOnActionListener);
    appNameEdit.setFilters(new InputFilter[]{renameFilter});

    if(project.inEditMode) {
        appNameEdit.setVisibility(View.VISIBLE);

        appNameEdit.setText(project.name);
        appNameEdit.setSelection(project.name.length());
        appNameEdit.requestFocus();
        appNameButton.setVisibility(View.INVISIBLE);

    } else {
        appNameEdit.setVisibility(View.INVISIBLE);
        appNameButton.setVisibility(View.VISIBLE);
        //dismissKeyBoard(appNameEdit, false);
    }

    //appNameEdit.setOnClickListener(appNameClickListener);

    TextView flashBtnText = (TextView) convertView.findViewById(R.id.project_item_text);
    flashBtnText.setTypeface(MBApp.getApp().getRobotoTypeface());
    LinearLayout sendBtnLayout = (LinearLayout) convertView.findViewById(R.id.sendBtn);
    sendBtnLayout.setTag(position);
    sendBtnLayout.setOnClickListener(sendBtnClickListener);

    ImageButton deleteBtn = (ImageButton) convertView.findViewById(R.id.deleteBtn);
    deleteBtn.setTag(position);
    deleteBtn.setOnClickListener(deleteBtnClickListener);
    deleteBtn.setEnabled(true);


    Drawable myIcon;
    if(project.runStatus) {
        flashBtnText.setText("");
        myIcon = convertView.getResources().getDrawable(R.drawable.green_btn);
    } else {
        flashBtnText.setText(R.string.flash);
        myIcon = convertView.getResources().getDrawable(R.drawable.blue_btn);
    }
    sendBtnLayout.setBackground(myIcon);

    sendBtnLayout.setClickable(true);
    return convertView;
}