Example usage for android.view View setBackgroundColor

List of usage examples for android.view View setBackgroundColor

Introduction

In this page you can find the example usage for android.view View setBackgroundColor.

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:org.level28.android.moca.ui.schedule.SessionListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final Resources res = view.getResources();

    // Get a hold on all view elements
    mListView = (ListView) view.findViewById(android.R.id.list);
    mProgressBar = (ProgressBar) view.findViewById(R.id.progressLoading);
    mEmptyView = (TextView) view.findViewById(android.R.id.empty);

    // Backward compatibility sucks
    if (!isHoneycomb) {
        // Force the Holo Light background color for this fragment on
        // gingerbread and lower
        view.setBackgroundColor(res.getColor(R.color.background_holo_light));

        // If we're running on Gingerbread or lower we have to override the
        // divider drawable for consistency
        mListView.setDivider(res.getDrawable(R.drawable.list_divider));
    }/*from w ww. jav a 2 s  .co  m*/

    // Set divider height to 2dp
    mListView.setDividerHeight(2);

    // Set item click listener
    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            onListItemClick((ListView) parent, view, position, id);
        }
    });

    mListView.setAdapter(mAdapter);
}

From source file:im.vector.adapters.VectorMessagesAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);

    if (null != view) {
        view.setBackgroundColor(Color.TRANSPARENT);
    }/*from   w  w  w  . j a va  2 s . c  o m*/

    return view;
}

From source file:com.samsistemas.calendarview.widget.CalendarView.java

/**
 * Initialize the calendar week layout, considers start day
 *//*from  w  w w  .ja  va  2 s. com*/
private void initWeekLayout() {
    TextView dayOfWeek;
    String dayOfTheWeekString;

    //Setting background color white
    View titleLayout = mView.findViewById(R.id.week_layout);
    titleLayout.setBackgroundColor(mWeekLayoutBackgroundColor);

    final String[] weekDaysArray = new DateFormatSymbols(getLocale()).getShortWeekdays();
    for (int i = 1; i < weekDaysArray.length; i++) {
        dayOfTheWeekString = weekDaysArray[i];
        int length = dayOfTheWeekString.length() < 3 ? dayOfTheWeekString.length() : 3;
        dayOfTheWeekString = dayOfTheWeekString.substring(0, length).toUpperCase();
        dayOfWeek = (TextView) mView.findViewWithTag(
                mContext.getString(R.string.day_of_week) + CalendarUtility.getWeekIndex(i, mCalendar));
        dayOfWeek.setText(dayOfTheWeekString);
        mIsCommonDay = true;
        if (totalDayOfWeekend().length != 0) {
            for (int weekend : totalDayOfWeekend()) {
                if (i == weekend) {
                    dayOfWeek.setTextColor(mWeekendColor);
                    mIsCommonDay = false;
                }
            }
        }

        if (mIsCommonDay) {
            dayOfWeek.setTextColor(mDayOfWeekTextColor);
        }

        if (null != getTypeface()) {
            dayOfWeek.setTypeface(getTypeface());
        }
    }
}

From source file:com.example.spencerdepas.translationapp.activities.DMVStudyActivity.java

private void showSelectQuestionDialog() {
    Log.d(TAG, "showAlertDialog");
    // Prepare grid view
    GridView gridView = new GridView(this);

    int questionSize = driverQuestions.getQuestions().size();
    List<Integer> mList = new ArrayList<Integer>();
    for (int i = 1; i < questionSize + 1; i++) {
        mList.add(i);/*  www  .j  ava2s .c  om*/
    }

    gridView.setAdapter(new ArrayAdapter<Integer>(this, R.layout.custom_list_item, mList) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);

            boolean hasBeenAnswered = hasBeenAnswered(position);
            Log.d(TAG, "hasBeenAnswered : " + hasBeenAnswered);
            int color = 0x00FFFFFF; // Transparent
            if (hasBeenAnswered) {

                if (driverQuestions.getQuestions().get(position).isAnsweredCorrectly()) {
                    //answer is correct
                    view.setBackgroundColor(getResources().getColor(R.color.colorForQuestionGrid));
                } else {
                    //answer is incorrect
                    view.setBackgroundColor(getResources().getColor(R.color.red));
                }

            } else {

                view.setBackgroundColor(color);
            }

            return view;
        }
    });
    gridView.setNumColumns(4);

    // Set grid view to alertDialog
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(gridView);
    builder.setTitle(getResources().getString(R.string.select_question));
    builder.setPositiveButton(getResources().getString(R.string.dialog_dismiss),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Log.d(TAG, getResources().getString(R.string.dialog_dismiss));
                    dialog.dismiss();
                }
            });

    final AlertDialog ad = builder.show();

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // do something here
            Log.d(TAG, "onclick");

            if (position == 0) {
                makePrevousButtonUnclickable();
            } else {
                makePrevousButtonClickable();
            }

            mNextButton.setText(getResources().getString(R.string.next_button));
            Log.d(TAG, "int pos : " + position);
            if (position == 193) {
                mNextButton.setText(getResources().getString(R.string.finish_studying));
            }

            goToSelectedQuestion(position);
            ad.dismiss();
        }
    });

}

From source file:org.medankulinar.MixListView.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    itemPosition = position;// w  w  w .  j  a  va 2  s .  c o  m
    if (convertView == null) {
        convertView = myInflater.inflate(R.layout.main, null);

        holder = new ViewHolder();
        holder.text = (TextView) convertView.findViewById(R.id.list_text);
        holder.description = (TextView) convertView.findViewById(R.id.description_text);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.text.setPadding(20, 8, 0, 0);
    holder.description.setPadding(20, 40, 0, 0);

    holder.text.setText(mixListView.getDataSourceMenu().get(position));
    holder.description.setText(mixListView.getDataSourceDescription().get(position));

    int colorPos = position % bgcolors.length;
    convertView.setBackgroundColor(bgcolors[colorPos]);
    holder.text.setTextColor(textcolors[colorPos]);
    holder.description.setTextColor(descriptioncolors[colorPos]);

    return convertView;
}

From source file:org.mythtv.client.ui.BackendStatusFragment.java

private View getUpcomingRecView(LayoutInflater inflater, Program program) {

    View view = (View) inflater.inflate(R.layout.backend_status_upcoming_list_item, null, false);

    // set category color
    View category = view.findViewById(R.id.upcoming_category);
    if (null != category)
        category.setBackgroundColor(mProgramHelper.getCategoryColor(program.getCategory()));

    // set upcoming_title
    TextView tView = (TextView) view.findViewById(R.id.upcoming_title);
    if (null != tView) {
        tView.setText(program.getTitle());
    }/*  w ww . j  av a  2  s.  co m*/

    // set upcoming_sub_title
    tView = (TextView) view.findViewById(R.id.upcoming_sub_title);
    if (null != tView) {
        tView.setText(program.getSubTitle());
    }

    // set upcoming_channel
    tView = (TextView) view.findViewById(R.id.upcoming_channel);
    if (null != tView) {
        tView.setText(program.getChannelInfo().getCallSign());
    }

    // set upcoming_start_time
    tView = (TextView) view.findViewById(R.id.upcoming_start_time);
    if (null != tView) {
        tView.setText(DateUtils.getDayTimeWithLocaleFormatting(
                program.getStartTime().withZone(DateTimeZone.getDefault()),
                getMainApplication().getClockType()));
    }

    // set upcoming_duration
    tView = (TextView) view.findViewById(R.id.upcoming_duration);
    if (null != tView) {
        tView.setText(Long.toString(program.getDurationInMinutes()));
    }

    return view;

}

From source file:org.jitsi.android.gui.call.VideoCallActivity.java

/**
 * Sets the security padlock background color.
 *
 * @param colorId the color resource id that will be used.
 *///  ww w  .j  a v  a  2 s  .c om
private void setPadlockColor(int colorId) {
    View padlockGroup = findViewById(R.id.security_group);
    int color = getResources().getColor(colorId);
    padlockGroup.setBackgroundColor(color);
}

From source file:og.android.tether.MainActivity.java

private void openAdBar() {
    LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View ad_view = li.inflate(R.layout.ad_view, null);
    ad_view.setBackgroundColor(Color.TRANSPARENT);

    final WindowManager wm = getWindowManager();
    WindowManager.LayoutParams wmParams = new WindowManager.LayoutParams();
    wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.gravity = Gravity.BOTTOM;//from  w w w. ja  v a2s  .co  m
    wmParams.y = 100;
    wmParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    wmParams.format = PixelFormat.TRANSLUCENT;

    wm.addView(ad_view, wmParams);

    View ad_open = ad_view.findViewById(R.id.ad_open);
    View ad_close = ad_view.findViewById(R.id.ad_close);

    OnClickListener adListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.ad_open:
                Log.i(MSG_TAG, "ad_open");
                Intent i = new Intent();
                i.setAction(Intent.ACTION_VIEW);
                i.addCategory(Intent.CATEGORY_BROWSABLE);
                i.setData(Uri.parse(
                        "market://details?id=com.opengarden.radiofreenet&referrer=utm_source%3Dog.android.tether%26utm_medium%3Dandroid%26utm_campaign%3Dbanner%26utm_content%3Dinstall"));
                try {
                    startActivity(i);
                } catch (android.content.ActivityNotFoundException e) {
                    Log.e(MSG_TAG, "", e);
                    MainActivity.this.application.displayToastMessage(e.toString());
                }
                break;

            case R.id.ad_close:
                Log.i(MSG_TAG, "ad_close");
                wm.removeView(ad_view);
                break;

            default:
                Log.i(MSG_TAG, "default");
                break;
            }
        }
    };
    ad_open.setOnClickListener(adListener);
    ad_close.setOnClickListener(adListener);
}

From source file:com.google.android.apps.muzei.settings.SettingsActivity.java

private void updateRenderLocally(boolean renderLocally) {
    if (mRenderLocally == renderLocally) {
        return;/*from  w  w w. j  a va  2 s. c o  m*/
    }

    mRenderLocally = renderLocally;

    final View uiContainer = findViewById(R.id.container);
    final ViewGroup localRenderContainer = (ViewGroup) findViewById(R.id.local_render_container);

    FragmentManager fm = getSupportFragmentManager();
    Fragment localRenderFragment = fm.findFragmentById(R.id.local_render_container);
    if (mRenderLocally) {
        if (localRenderFragment == null) {
            fm.beginTransaction()
                    .add(R.id.local_render_container, MuzeiRendererFragment.createInstance(false, false))
                    .commit();
        }
        if (localRenderContainer.getAlpha() == 1) {
            localRenderContainer.setAlpha(0);
        }
        localRenderContainer.setVisibility(View.VISIBLE);
        localRenderContainer.animate().alpha(1).setDuration(2000).withEndAction(null);
        uiContainer.setBackgroundColor(0x00000000); // for ripple touch feedback
    } else {
        if (localRenderFragment != null) {
            fm.beginTransaction().remove(localRenderFragment).commit();
        }
        localRenderContainer.animate().alpha(0).setDuration(1000).withEndAction(new Runnable() {
            @Override
            public void run() {
                localRenderContainer.setVisibility(View.GONE);
            }
        });
        uiContainer.setBackground(null);
    }
}

From source file:com.android.calculator2.Calculator.java

private void reveal(View sourceView, int colorRes, AnimatorListener listener) {
    final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay();

    final Rect displayRect = new Rect();
    mDisplayView.getGlobalVisibleRect(displayRect);

    // Make reveal cover the display and status bar.
    final View revealView = new View(this);
    revealView.setBottom(displayRect.bottom);
    revealView.setLeft(displayRect.left);
    revealView.setRight(displayRect.right);
    revealView.setBackgroundColor(getResources().getColor(colorRes));
    groupOverlay.add(revealView);/*from  w w w .  j ava 2  s  . c  o  m*/

    final int[] clearLocation = new int[2];
    sourceView.getLocationInWindow(clearLocation);
    clearLocation[0] += sourceView.getWidth() / 2;
    clearLocation[1] += sourceView.getHeight() / 2;

    final int revealCenterX = clearLocation[0] - revealView.getLeft();
    final int revealCenterY = clearLocation[1] - revealView.getTop();

    final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
    final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
    final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
    final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

    final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
            revealCenterY, 0.0f, revealRadius);
    revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    revealAnimator.addListener(listener);

    final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(revealAnimator).before(alphaAnimator);
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            groupOverlay.remove(revealView);
            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}