Example usage for android.widget LinearLayout setBackground

List of usage examples for android.widget LinearLayout setBackground

Introduction

In this page you can find the example usage for android.widget LinearLayout setBackground.

Prototype

public void setBackground(Drawable background) 

Source Link

Document

Set the background to a given Drawable, or remove the background.

Usage

From source file:edu.ptu.navpattern.tooltip.Tooltip.java

private View getContentView(final Builder builder) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(builder.mBackgroundColor);
    drawable.setCornerRadius(builder.mCornerRadius);
    LinearLayout vgContent = new LinearLayout(builder.mContext);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        vgContent.setBackground(drawable);
    } else {/*from w w w . j  ava2s  . c  om*/
        //noinspection deprecation
        vgContent.setBackgroundDrawable(drawable);
    }
    int padding = (int) builder.mPadding;
    vgContent.setPadding(padding, padding, padding, padding);
    vgContent.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    textViewParams.gravity = Gravity.CENTER;
    textViewParams.topMargin = 1;
    vgContent.setLayoutParams(textViewParams);
    vgContent.setDividerDrawable(vgContent.getResources().getDrawable(R.drawable.divider_line));
    vgContent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);

    if (builder.itemText != null && builder.itemText.length > 0) {
        for (int i = 0; i < builder.itemText.length; i++) {

            TextView textView = new TextView(builder.mContext);
            textView.setText(builder.itemText[i]);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 44);
            textView.setTextColor(0xffffffff);
            textView.setGravity(Gravity.CENTER_VERTICAL);
            if (builder.itemLogo != null && builder.itemLogo.length > i) {
                Drawable drawableLeft = builder.mContext.getResources().getDrawable(builder.itemLogo[i]);
                /// ??,??.
                //                    drawableLeft.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                //                    textView.setCompoundDrawables(drawableLeft, null, null, null);
                //                    textView.setCompoundDrawablePadding(4);
                //                    textView.setBackgroundDrawable(drawableLeft);
                LinearLayout linearLayout = new LinearLayout(builder.mContext);
                linearLayout.setMinimumHeight((int) dpToPx(44f));
                linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.setGravity(Gravity.CENTER_VERTICAL);
                ImageView icon = new ImageView(builder.mContext);
                icon.setImageDrawable(drawableLeft);
                linearLayout.addView(icon);
                linearLayout.addView(textView);
                vgContent.addView(linearLayout);
                final int position = i;
                linearLayout.setClickable(false);
                linearLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v,
                                MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                                        MotionEvent.ACTION_UP, v.getLeft() + 5, v.getTop() + 5, 0));
                    }
                });
            } else {
                vgContent.addView(textView);
                final int position = i;
                textView.setClickable(false);
                textView.setMinimumHeight((int) dpToPx(44f));
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v, null);
                    }
                });
            }
        }

    }

    mArrowView = new ImageView(builder.mContext);
    mArrowView.setImageDrawable(builder.mArrowDrawable);

    LinearLayout.LayoutParams arrowLayoutParams;
    if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight,
                0);
    } else {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth,
                0);
    }
    arrowLayoutParams.gravity = Gravity.CENTER;
    mArrowView.setLayoutParams(arrowLayoutParams);

    mContentView = new LinearLayout(builder.mContext);
    mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL
            : LinearLayout.VERTICAL);

    padding = (int) dpToPx(5);

    switch (mGravity) {
    case Gravity.START:
        mContentView.setPadding(0, 0, padding, 0);
        break;
    case Gravity.TOP:
    case Gravity.BOTTOM:
        mContentView.setPadding(padding, 0, padding, 0);
        break;
    case Gravity.END:
        mContentView.setPadding(padding, 0, 0, 0);
        break;
    }

    if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
        mContentView.addView(vgContent);
        mContentView.addView(mArrowView);
    } else {
        mContentView.addView(mArrowView);
        mContentView.addView(vgContent);
    }

    if (builder.isCancelable || builder.isDismissOnClick) {
        mContentView.setOnTouchListener(mTouchListener);
    }
    return mContentView;
}

From source file:com.sj.android.appusage.activities.UsageListFragment.java

private void initActionBar() {

    mActionBar = mActivity.getActionBar();
    mActionBar.setDisplayShowTitleEnabled(false);
    mActionBar.setDisplayHomeAsUpEnabled(false);
    LayoutInflater mInflater = LayoutInflater.from(mActivity);

    View customView = mInflater.inflate(R.layout.custom_action_bar, null);
    LinearLayout layout = (LinearLayout) customView.findViewById(R.id.action_title_view);
    TextView mTitleTextView = (TextView) customView.findViewById(R.id.title_text);
    mTitleTextView.setTextColor(getResources().getColor(android.R.color.white));
    mTitleTextView.setText(getString(R.string.app_name));
    layout.setBackground(null);

    mActionBar.setCustomView(customView);
    mActionBar.setDisplayShowCustomEnabled(true);

}

From source file:com.weebly.opus1269.copyeverywhere.ui.main.MainActivity.java

/**
 * Initialize the NavigationView//from  ww  w . ja v a 2 s. co  m
 *
 */
private void setupNavigationView() {
    final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView == null) {
        return;
    }
    navigationView.addOnLayoutChangeListener(this);

    // Handle click on header
    final View hView = navigationView.getHeaderView(0);
    hView.setOnClickListener(this);

    // set Devices menu state
    final Menu menu = navigationView.getMenu();
    final MenuItem deviceItem = menu.findItem(R.id.nav_devices);
    deviceItem.setEnabled(Prefs.isGcmRegistered());

    // set users avatar
    final String photoUri = Prefs.getPersonPhoto();
    final ImageView photo = (ImageView) hView.findViewById(R.id.personPhoto);
    if (!photoUri.isEmpty()) {
        photo.setImageAlpha(255);
        new LoadProfileImage(photo).execute(photoUri);
    } else {
        photo.setImageResource(R.drawable.ic_account_circle_24dp);
        photo.setImageAlpha(75);
    }

    // set users Google+ cover photo
    final String coverPhotoUri = Prefs.getPersonCoverPhoto();
    final LinearLayout coverPhoto = (LinearLayout) hView.findViewById(R.id.navHeader);
    if (!coverPhotoUri.isEmpty()) {
        new LoadCoverImage(coverPhoto).execute(coverPhotoUri);
    } else {
        final Drawable drawable = ContextCompat.getDrawable(this, R.drawable.side_nav_bar);
        coverPhoto.setBackground(drawable);
    }

    // set users account information
    final TextView name = (TextView) hView.findViewById(R.id.personName);
    final TextView email = (TextView) hView.findViewById(R.id.personEmail);
    name.setText(Prefs.getPersonName());
    email.setText(Prefs.getPersonEmail());
}