Example usage for android.view View setBackgroundResource

List of usage examples for android.view View setBackgroundResource

Introduction

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

Prototype

@RemotableViewMethod
public void setBackgroundResource(@DrawableRes int resid) 

Source Link

Document

Set the background to a given resource.

Usage

From source file:fr.enseirb.odroidx.remote_client.MainActivity.java

@Override
public void onClick(View v) {
    Log.v(TAG, "click event on a button");
    v.setBackgroundResource(R.color.blue_light);

    if (v == button_play)
        sendMessageToSTB(Commands.VIDEO_PLAY);
    else if (v == button_pause)
        sendMessageToSTB(Commands.VIDEO_PAUSE);
    else if (v == button_stop)
        sendMessageToSTB(Commands.VIDEO_STOP);
    else if (v == button_previous)
        sendMessageToSTB(Commands.VIDEO_PREVIOUS);
    else if (v == button_next)
        sendMessageToSTB(Commands.VIDEO_NEXT);
    else if (v == button_up)
        sendMessageToSTB(Commands.MOVE_UP);
    else if (v == button_down)
        sendMessageToSTB(Commands.MOVE_DOWN);
    else if (v == button_left)
        sendMessageToSTB(Commands.MOVE_LEFT);
    else if (v == button_right)
        sendMessageToSTB(Commands.MOVE_RIGHT);
    else if (v == button_select)
        sendMessageToSTB(Commands.SELECT);
    else if (v == button_back)
        sendMessageToSTB(Commands.BACK);
    else if (v == button_home)
        sendMessageToSTB(Commands.HOME);
    else if (v == button_sound_mute)
        sendMessageToSTB(Commands.SOUND_MUTE);
    else if (v == button_sound_plus)
        sendMessageToSTB(Commands.SOUND_PLUS);
    else if (v == button_sound_minus)
        sendMessageToSTB(Commands.SOUND_MINUS);
    else if (v == button_enter_text) {

        AlertDialog.Builder editalert = new AlertDialog.Builder(this);
        editalert.setTitle("Message to send to the STB");
        final EditText input = new EditText(this);
        editalert.setView(input);// w  w w.j a  va2s . com

        editalert.setPositiveButton("Send it", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

                sendMessageToSTB(Commands.USER_TEXT, input.getText().toString());
            }
        });

        editalert.show();
    }
}

From source file:net.yanzm.mth.MaterialTabHost.java

/**
 * add new tab with specified view//from  w w w  .jav  a 2 s . c  om
 *
 * @param view tab view
 */
public void addTab(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setBackgroundResource(R.drawable.mth_tab_widget_background_ripple);

    } else {
        // create background using colorControlActivated
        StateListDrawable d = new StateListDrawable();
        d.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(colorControlActivated));
        d.setAlpha(180);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            view.setBackground(d);
        } else {
            view.setBackgroundDrawable(d);
        }
    }

    int tabId = tabWidget.getTabCount();

    addTab(newTabSpec(String.valueOf(tabId)).setIndicator(view).setContent(android.R.id.tabcontent));
}

From source file:com.android.contacts.common.list.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    View tabView;/*  w ww .  j av  a  2 s  .c o m*/
    if (mTabIcons != null && position < mTabIcons.length) {
        View layout = LayoutInflater.from(getContext()).inflate(R.layout.unread_count_tab, null);
        View iconView = layout.findViewById(R.id.icon);
        iconView.setBackgroundResource(mTabIcons[position]);
        iconView.setContentDescription(tabTitle);
        TextView textView = (TextView) layout.findViewById(R.id.count);
        if (mUnreadCounts != null && mUnreadCounts[position] > 0) {
            textView.setText(Integer.toString(mUnreadCounts[position]));
            textView.setVisibility(View.VISIBLE);
            iconView.setContentDescription(
                    getResources().getQuantityString(R.plurals.tab_title_with_unread_items,
                            mUnreadCounts[position], tabTitle.toString(), mUnreadCounts[position]));
        } else {
            textView.setVisibility(View.INVISIBLE);
            iconView.setContentDescription(tabTitle);
        }
        tabView = layout;
    } else {
        final TextView textView = new TextView(getContext());
        textView.setText(tabTitle);
        textView.setBackgroundResource(R.drawable.view_pager_tab_background);

        // Assign various text appearance related attributes to child views.
        if (mTextStyle > 0) {
            textView.setTypeface(textView.getTypeface(), mTextStyle);
        }
        if (mTextSize > 0) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
        }
        if (mTextColor != null) {
            textView.setTextColor(mTextColor);
        }
        textView.setAllCaps(mTextAllCaps);
        textView.setGravity(Gravity.CENTER);

        tabView = textView;
    }

    tabView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    tabView.setOnLongClickListener(new OnTabLongClickListener(position));

    tabView.setPadding(mSidePadding, 0, mSidePadding, 0);

    mTabStrip.addView(tabView, position,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1));

    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        tabView.setSelected(true);
    }
}

From source file:com.nadmm.airports.wx.WxMapFragmentBase.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflate(R.layout.wx_map_detail_view);
    if (mLabel != null && mLabel.length() > 0) {
        TextView tv = (TextView) v.findViewById(R.id.wx_map_label);
        tv.setText(mLabel);//from   w w w .j ava  2s.  co m
        tv.setVisibility(View.VISIBLE);
    }

    if (mHelpText != null && mHelpText.length() > 0) {
        TextView tv = (TextView) v.findViewById(R.id.help_text);
        tv.setText(mHelpText);
        tv.setVisibility(View.VISIBLE);
    }

    OnClickListener listener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mPendingRow == null) {
                mPendingRow = v;
                String code = getMapCode(v);
                requestWxMap(code);
            }
        }
    };

    LinearLayout layout = (LinearLayout) v.findViewById(R.id.wx_map_layout);
    for (int i = 0; i < mWxMapCodes.length; ++i) {
        View row = addProgressRow(layout, mWxMapNames[i]);
        row.setTag(mWxMapCodes[i]);
        row.setOnClickListener(listener);
        row.setBackgroundResource(R.drawable.row_selector_middle);
    }

    if (mWxTypeCodes != null) {
        TextView tv = (TextView) v.findViewById(R.id.wx_map_type_label);
        tv.setVisibility(View.VISIBLE);
        layout = (LinearLayout) v.findViewById(R.id.wx_map_type_layout);
        layout.setVisibility(View.VISIBLE);
        mSpinner = (Spinner) v.findViewById(R.id.map_type);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_spinner_item, mWxTypeNames);
        adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
        mSpinner.setAdapter(adapter);
    }

    return v;
}

From source file:com.veniosg.dir.android.fragment.SearchListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    int backgroundColorRes = getThemedResourceId(getActivity(), android.R.attr.colorBackground);
    view.setBackgroundResource(backgroundColorRes);

    mRecyclerView = (RecyclerView) view.findViewById(android.R.id.list);
    mFlipper = (WaitingViewFlipper) view.findViewById(R.id.flipper);
    mQueryView = (EditText) view.findViewById(R.id.searchQuery);
    mUpView = view.findViewById(R.id.homeAsUp);
    mProgressIndicator = view.findViewById(R.id.progressHint);

    setupStaticViews();//from  w  w  w  . ja  va 2s .co  m
    setupList();
}

From source file:com.maedi.user.godok.v1.viewpagerindicator.TabPageIndicator.java

@SuppressLint("ResourceAsColor")
private void changeTabLayout(int item, String title) {
    PagerAdapter adapter = mViewPager.getAdapter();
    final int tabCount = mTabLayout.getChildCount();
    for (int i = 0; i < tabCount; i++) {
        final View child = mTabLayout.getChildAt(i);

        if (i == 1)
            child.setBackgroundResource(R.drawable.tab_view);//child.setPadding(0, 0, 10, 0);//L,T,R,B
        ((TextView) child).setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
        //((TextView) child).setTextColor(getResources().getColor(R.color.tab_button_text));
        ((TextView) child).setTextSize(15);
        ((TextView) child).setGravity(Gravity.CENTER);
        ((TextView) child).setTextColor(getResources().getColor(R.color.white));

        /*//from www.  j  a va 2 s  .c  o  m
         * for advance menu left selected
         * by medi
         */
        if (null != title && !title.equalsIgnoreCase("")) {
            CharSequence originalTitle = adapter.getPageTitle(i);
            ((TextView) child).setText(originalTitle);
        }

        final boolean isSelected = (i == item);
        child.setSelected(isSelected);
        if (isSelected) {
            animateToTab(item);
            ((TextView) child).setTypeface(Typeface.DEFAULT, Typeface.BOLD);
            //((TextView) child).setTextColor(getResources().getColor(R.color.tab_button_text_selected));

            if (null != title && !title.equalsIgnoreCase("")) {
                ((TextView) child).setText(title);
            }

        }
    }
}

From source file:com.falcon.nester.AboutActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.about);/*  ww w.  jav  a2s  .c  o m*/

    View.OnClickListener onClickListener = new View.OnClickListener() {
        public void onClick(View v) {
            btnIntroduce.setBackgroundResource(R.drawable.btn_bg_blue3);
            btnLicense.setBackgroundResource(R.drawable.btn_bg_blue3);
            btnLegal.setBackgroundResource(R.drawable.btn_bg_blue3);
            btnUpdate.setBackgroundResource(R.drawable.btn_bg_blue3);
            v.setBackgroundResource(R.drawable.btn_bg_blue6);
            switch (v.getId()) {
            case R.id.btn_introduce:
                setAboutInfo(R.string.introduce, R.string.introduce_asset);
                break;
            case R.id.btn_license:
                setAboutInfo(R.string.license, R.string.license_asset);
                break;
            case R.id.btn_legal:
                setAboutInfo(R.string.legal, R.string.legal_asset);
                break;
            case R.id.btn_update:
                break;
            }
            //            TextView tv = (TextView)findViewById(R.id.about_info);
            //            tv.invalidate();
            //            scvInfo.invalidate();
        }
    };

    setAboutInfo(R.string.introduce, R.string.introduce_asset);
    //setAboutInfo(R.string.license, R.string.license_asset);

    scvInfo = (ScrollView) this.findViewById(R.id.scrollview_info);
    btnIntroduce = (Button) this.findViewById(R.id.btn_introduce);
    btnIntroduce.setOnClickListener(onClickListener);
    btnLicense = (Button) this.findViewById(R.id.btn_license);
    btnLicense.setOnClickListener(onClickListener);
    btnLegal = (Button) this.findViewById(R.id.btn_legal);
    btnLegal.setOnClickListener(onClickListener);
    btnUpdate = (Button) this.findViewById(R.id.btn_update);
    btnUpdate.setOnClickListener(onClickListener);
}

From source file:com.esminis.server.library.dialog.about.AboutViewImpl.java

private void setupTabTitles(TabHost tabhost) {
    final int tabCount = tabhost.getTabWidget() == null ? 0 : tabhost.getTabWidget().getTabCount();
    for (int i = 0; i < tabCount; i++) {
        View viewTab = tabhost.getTabWidget().getChildTabViewAt(i);
        if (viewTab != null) {
            View textView = viewTab.findViewById(android.R.id.title);
            if (textView != null && textView instanceof TextView) {
                ((TextView) textView).setGravity(Gravity.CENTER);
            }// w  w w  . j  a va 2 s.  c o m
            viewTab.setBackgroundResource(R.drawable.tab_indicator);
        }
    }
}

From source file:fr.univsavoie.ltp.client.map.Popup.java

/**
  * Afficher sur la map un popup qui affiche les
  * informations de l'utilisateur connect.
  *//*from   w w w  .j ava  2s. c  om*/
public final void popupDisplayUserInfos() {
    DisplayMetrics dm = new DisplayMetrics();
    this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    //final int height = dm.heightPixels;
    final int width = dm.widthPixels;

    int popupWidth = (int) (width * 0.75);
    //int popupHeight = height / 2;

    // Inflate the popup_layout.xml
    LinearLayout viewGroup = (LinearLayout) this.activity.findViewById(R.id.popupAccount);
    LayoutInflater layoutInflater = (LayoutInflater) this.activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View layout = layoutInflater.inflate(R.layout.popup_account, viewGroup);
    layout.setBackgroundResource(R.drawable.popup_gradient);

    // Crer le PopupWindow
    final PopupWindow popupUserInfos = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true);
    popupUserInfos.setBackgroundDrawable(new BitmapDrawable());
    popupUserInfos.setOutsideTouchable(true);

    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    final int OFFSET_X = 0;
    final int OFFSET_Y = 0;

    // Displaying the popup at the specified location, + offsets.
    this.activity.findViewById(R.id.layoutMain).post(new Runnable() {
        public void run() {
            popupUserInfos.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y);
        }
    });

    /*
     * Evenements composants du PopupWindow
     */

    // Ecouteur d'vnement sur le bouton pour se dconnecter
    Button close = (Button) layout.findViewById(R.id.close);
    close.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            popupUserInfos.dismiss();
        }
    });
}

From source file:com.example.demo_highlights.slidingmenu.activity.SlidingActivity.java

protected void setMenuBackground() {

    //       Log.d(TAG, "??");
    getLayoutInflater().setFactory(new Factory() {

        @Override//from   w  ww . j  av a 2  s  .co m
        public View onCreateView(String name, Context context, AttributeSet attrs) {
            // TODO Auto-generated method stub
            if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
                //??Android123?????android?packageName?

                try {
                    LayoutInflater f = getLayoutInflater();
                    final View view = f.createView(name, null, attrs); //?

                    new Handler().post(new Runnable() {
                        public void run() {
                            view.setBackgroundResource(R.drawable.bpush_top_bg);
                        }
                    });
                    return view;
                } catch (InflateException e) {
                } catch (ClassNotFoundException e) {
                }
            }

            return null;
        }
    });
}