Example usage for android.widget RelativeLayout setBackgroundResource

List of usage examples for android.widget RelativeLayout setBackgroundResource

Introduction

In this page you can find the example usage for android.widget RelativeLayout setBackgroundResource.

Prototype

@RemotableViewMethod
public void setBackgroundResource(@DrawableRes int resid) 

Source Link

Document

Set the background to a given resource.

Usage

From source file:com.ogunwale.android.app.yaps.ui.PhotosSimpleCursorAdapter.java

private void setDefaultBackground(Context context, RelativeLayout v) {
    v.setBackgroundResource(android.R.drawable.screen_background_dark_transparent);
}

From source file:es.uma.lcc.lockpic.SelectorActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Button btnForward, btnBack, btnFaces;
    RelativeLayout layout = new RelativeLayout(this);
    layout.setBackgroundResource(R.drawable.background_gradient);

    mPath = getIntent().getStringExtra("path");

    SelectorActivityBundle bundle = (SelectorActivityBundle) getLastCustomNonConfigurationInstance();
    if (bundle != null) {
        mDrawView = new DrawView(this, mPath, false);
        mDrawView.setRectangles(bundle.getRectangles());
        mDrawView.setViewMode(bundle.getViewMode());
        mDrawView.setAspectRate(bundle.getAspectRate());
    } else {/*ww  w.  j  a v  a2s  .co  m*/
        mDrawView = new DrawView(this, mPath, true);
    }
    mDrawView.setId(1);

    RelativeLayout.LayoutParams lpDrawView = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    lpDrawView.addRule(RelativeLayout.CENTER_VERTICAL);
    mDrawView.setLayoutParams(lpDrawView);
    layout.addView(mDrawView, lpDrawView);

    btnForward = new Button(this);
    btnForward.setText(R.string.selectorForwardButton);
    btnForward.setId(2);
    btnForward.setOnClickListener(new forwardButtonListener());
    RelativeLayout.LayoutParams lpButton = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    lpButton.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    lpButton.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    layout.addView(btnForward, lpButton);

    btnBack = new Button(this);
    btnBack.setText(R.string.selectorBackButton);
    btnBack.setId(3);
    btnBack.setOnClickListener(new backButtonListener());
    lpButton = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lpButton.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    lpButton.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    layout.addView(btnBack, lpButton);

    btnFaces = new Button(this);
    btnFaces.setText(R.string.facesButton);
    btnFaces.setId(4);
    btnFaces.setOnClickListener(new FacesButtonListener());
    if (!isViewSelectingRegions())
        btnFaces.setVisibility(View.INVISIBLE);
    lpButton = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lpButton.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    lpButton.addRule(RelativeLayout.CENTER_HORIZONTAL);
    layout.addView(btnFaces, lpButton);

    setContentView(layout);
}

From source file:org.hansel.myAlert.WelcomeInfo.WelcomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup rootView = (ViewGroup) inflater.inflate(org.hansel.myAlert.R.layout.welcome, container, false);

    TextView texto = (TextView) rootView.findViewById(R.id.textView1);
    RelativeLayout layout = (RelativeLayout) rootView.findViewById(R.id.bigImage);
    switch (number) {
    case 0://from   www.  jav  a  2s . c  o m
        texto.setText(getResources().getString(R.string.slide0));
        //icono.setImageResource(R.drawable.slide0);
        layout.setBackgroundResource(R.drawable.slide0);
        break;
    case 1:
        texto.setText(getResources().getString(R.string.slide1));
        //icono.setImageResource(R.drawable.slide1);
        layout.setBackgroundResource(R.drawable.slide1);
        break;
    case 2:
        texto.setText(getResources().getString(R.string.slide2));
        //icono.setImageResource(R.drawable.icono2);
        layout.setBackgroundResource(R.drawable.slide2);
        break;
    case 3:
        texto.setText(getResources().getString(R.string.slide3));
        //icono.setImageResource(R.drawable.icono1);
        layout.setBackgroundResource(R.drawable.slide3);
        break;
    case 4:
        texto.setText(getResources().getString(R.string.slide4));
        //icono.setImageResource(R.drawable.icono2);
        layout.setBackgroundResource(R.drawable.slide4);
        break;
    case 5:
        texto.setText(getResources().getString(R.string.slide5));
        //icono.setImageResource(R.drawable.icono3);
        layout.setBackgroundResource(R.drawable.slide5);
        break;
    }

    return rootView;

}

From source file:me.ziccard.secureit.fragment.EmptyFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if ((savedInstanceState != null) && savedInstanceState.containsKey(CONTENT)) {
        mContent = savedInstanceState.getString(CONTENT);
    }/*  w  w w  .ja va2s.com*/

    TextView text = new TextView(getActivity());
    text.setGravity(Gravity.CENTER);
    text.setText(mContent);
    text.setTextSize(20 * getResources().getDisplayMetrics().density);

    RelativeLayout layout = new RelativeLayout(getActivity());
    layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    layout.setGravity(Gravity.CENTER);

    RelativeLayout alert = new RelativeLayout(getActivity());
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    params.leftMargin = 20;
    params.rightMargin = 20;
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    alert.setLayoutParams(params);
    alert.setBackgroundResource(R.drawable.red_back);
    alert.setPadding(30, 0, 30, 0);
    alert.addView(text);
    layout.addView(alert);

    return layout;
}

From source file:com.ehret.mixit.fragment.PeopleDetailFragment.java

private void addPeopleLink(Member membre) {
    //On vide les lments
    linkLayout.removeAllViews();//from  w  ww .j a va  2 s . c  o  m

    //On affiche les liens que si on a recuperer des choses
    if (membre != null && membre.getSharedLinks() != null && !membre.getSharedLinks().isEmpty()) {

        //On ajoute un table layout
        TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
        TableLayout tableLayout = new TableLayout(getActivity().getBaseContext());
        tableLayout.setLayoutParams(tableParams);

        if (mInflater != null && membre.getSharedLinks().size() > 0) {
            for (final Link link : membre.getSharedLinks()) {
                RelativeLayout row = (RelativeLayout) mInflater.inflate(R.layout.item_link, tableLayout, false);
                row.setBackgroundResource(R.drawable.row_transparent_background);
                //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
                TextView link_text = (TextView) row.findViewById(R.id.link_text);
                link_text.setText(Html.fromHtml(String.format("%s : <a href=\"%s\">%s</a>", link.getRel(),
                        link.getHref(), link.getHref())));
                link_text.setBackgroundColor(Color.TRANSPARENT);
                link_text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse(link.getHref()));
                        getActivity().startActivity(in);
                    }

                });
                tableLayout.addView(row);
            }
        } else {
            RelativeLayout row = (RelativeLayout) mInflater.inflate(R.layout.item_link, tableLayout, false);
            row.setBackgroundResource(R.drawable.row_transparent_background);
            //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
            TextView link_text = (TextView) row.findViewById(R.id.link_text);
            link_text.setText("Aucun lien");
            link_text.setBackgroundColor(Color.TRANSPARENT);
            tableLayout.addView(row);
        }
        linkLayout.addView(tableLayout);
    } else {
        titleLinks.getLayoutParams().height = 0;
    }
}

From source file:com.cssweb.android.base.BaseActivity.java

protected void changeTitleBg() {
    RelativeLayout l = (RelativeLayout) findViewById(R.id.zr_headerBar);
    l.setBackgroundResource(R.drawable.njzq_title_red_bg);
}

From source file:de.tobiasbielefeld.solitaire.ui.GameManager.java

private void loadBackgroundColor() {
    RelativeLayout layout_background = (RelativeLayout) findViewById(R.id.mainRelativeLayoutGame);

    if (layout_background != null) {
        switch (getSharedString(getString(R.string.pref_key_background_color), "2")) {
        case "1":
            layout_background.setBackgroundResource(R.drawable.background_color_blue);
            break;
        case "2":
            layout_background.setBackgroundResource(R.drawable.background_color_green);
            break;
        case "3":
            layout_background.setBackgroundResource(R.drawable.background_color_red);
            break;
        case "4":
            layout_background.setBackgroundResource(R.drawable.background_color_yellow);
            break;
        case "5":
            layout_background.setBackgroundResource(R.drawable.background_color_orange);
            break;
        case "6":
            layout_background.setBackgroundResource(R.drawable.background_color_purple);
            break;
        }/*from  www  . j  a v  a  2 s .  com*/
    }
}

From source file:com.foxconn.lib.welcome.license.TestFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.welcome_content, null);

    TextView welcome_content_subject_tv, welcome_content_subject_detail_tv;

    welcome_content_subject_tv = (TextView) layout.findViewById(R.id.welcome_content_subject_tv);

    welcome_content_subject_detail_tv = (TextView) layout.findViewById(R.id.welcome_content_subject_detail_tv);

    ImageView welcome_content_iconlay = (ImageView) layout.findViewById(R.id.welcome_content_iconlay)
            .findViewById(R.id.welcome_content_iconlay_iv);

    switch (content) {
    case 0:// www.j  a v  a  2 s.  co m
        layout.setBackgroundResource(R.drawable.qo_startup_screen1);
        welcome_content_iconlay.setImageResource(R.drawable.icon);
        break;
    case 1:
        layout.setBackgroundResource(R.drawable.qo_startup_screen2);

        welcome_content_subject_tv.setText(getString(R.string.emm_license_welcome_pager2_title));
        welcome_content_subject_detail_tv.setText(getString(R.string.emm_license_welcome_pager2_content));
        break;
    case 2:
        layout.setBackgroundResource(R.drawable.qo_startup_screen3);
        welcome_content_iconlay.setImageResource(R.drawable.icon);
        welcome_content_subject_tv.setText(getString(R.string.emm_license_welcome_pager3_title));
        welcome_content_subject_detail_tv.setText(getString(R.string.emm_license_welcome_pager3_content));
        break;
    default:
        break;
    }

    return layout;
}

From source file:com.cssweb.android.base.BaseActivity.java

protected void changeBG() {
    RelativeLayout r = (RelativeLayout) findViewById(R.id.njzq_main_jlp);
    int level = TradeUser.getInstance().getUserLevel();
    switch (level) {
    case 1:/*from w  ww.ja  va  2  s .  c  om*/
        r.setBackgroundResource(R.drawable.njzq_main_licai_bg);
        break;
    case 2:
        r.setBackgroundResource(R.drawable.njzq_main_licai_bg);
        break;
    case 3:
        r.setBackgroundResource(R.drawable.njzq_main_jin_bg);
        break;
    case 4:
        r.setBackgroundResource(R.drawable.njzq_main_baijin_bg);
        break;
    case 5:
        r.setBackgroundResource(R.drawable.njzq_main_zuanshi_bg);
        break;
    default:
        r.setBackgroundResource(R.drawable.njzq_main_fk_bg);
        break;
    }
}

From source file:at.alladin.rmbt.android.fragments.history.RMBTFilterFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);

    view = inflater.inflate(R.layout.history_filter, container, false);

    deviceListView = (LinearLayout) view.findViewById(R.id.deviceList);
    networkListView = (LinearLayout) view.findViewById(R.id.networkList);

    final RelativeLayout resultLimitView = (RelativeLayout) view.findViewById(R.id.Limit25Wrapper);
    limit25CheckBox = (CheckBox) view.findViewById(R.id.Limit25CheckBox);

    if (activity.getHistoryResultLimit() == 250)
        limit25CheckBox.setChecked(true);
    else/*from  ww w .  j av  a 2  s  . c  o m*/
        limit25CheckBox.setChecked(false);

    resultLimitView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            if (limit25CheckBox.isChecked()) {
                limit25CheckBox.setChecked(false);
                activity.setHistoryResultLimit(0);
            } else {
                limit25CheckBox.setChecked(true);
                activity.setHistoryResultLimit(250);
            }

        }

    });

    devicesToShow = activity.getHistoryFilterDevicesFilter();
    networksToShow = activity.getHistoryFilterNetworksFilter();

    if (devicesToShow == null && networksToShow == null) {
        devicesToShow = new ArrayList<String>();
        networksToShow = new ArrayList<String>();
    }

    final float scale = activity.getResources().getDisplayMetrics().density;

    final int leftRightItem = Helperfunctions.dpToPx(5, scale);
    // int topBottomItem = Helperfunctions.dpToPx(5, scale);

    // int leftRightDiv = Helperfunctions.dpToPx(0, scale);
    // int topBottomDiv = Helperfunctions.dpToPx(0, scale);
    final int heightDiv = Helperfunctions.dpToPx(1, scale);

    // int topBottomImg = Helperfunctions.dpToPx(1, scale);

    final String historyDevices[] = activity.getHistoryFilterDevices();

    if (historyDevices != null) {

        for (int i = 0; i < historyDevices.length; i++) {

            final RelativeLayout singleItemLayout = new RelativeLayout(activity); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item);

            singleItemLayout.setId(i);
            singleItemLayout.setClickable(true);
            singleItemLayout.setBackgroundResource(R.drawable.list_selector);

            singleItemLayout.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

            final TextView itemTitle = new TextView(activity, null, R.style.textMediumLight);

            RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.MATCH_PARENT);
            layout.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            layout.addRule(RelativeLayout.CENTER_VERTICAL);

            // itemTitle.setLayoutParams(layout);
            itemTitle.setGravity(Gravity.LEFT);
            itemTitle.setPadding(leftRightItem, 0, leftRightItem, 0);
            itemTitle.setText(historyDevices[i]);

            singleItemLayout.addView(itemTitle, layout);

            final CheckBox itemCheck = new CheckBox(activity);

            layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            layout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            layout.addRule(RelativeLayout.CENTER_VERTICAL);

            // itemCheck.setLayoutParams(layout);

            itemCheck.setGravity(Gravity.RIGHT);
            itemCheck.setPadding(leftRightItem, 0, leftRightItem, 0);
            itemCheck.setOnClickListener(null);
            itemCheck.setClickable(false);
            itemCheck.setId(i + historyDevices.length);

            if (devicesToShow.isEmpty() || devicesToShow.contains(historyDevices[i]))
                itemCheck.setChecked(true);
            else
                itemCheck.setChecked(false);

            singleItemLayout.addView(itemCheck, layout);

            // layout = new
            // RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
            // RelativeLayout.LayoutParams.WRAP_CONTENT);

            // singleItemLayout.setLayoutParams(layout);

            singleItemLayout.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(final View v) {
                    final CheckBox check = (CheckBox) v.findViewById(v.getId() + historyDevices.length);
                    if (check.isChecked()) {
                        check.setChecked(false);
                        devicesToShow.remove(historyDevices[v.getId()]);
                    } else {
                        check.setChecked(true);
                        devicesToShow.add(historyDevices[v.getId()]);
                    }

                }

            });

            deviceListView.addView(singleItemLayout);

            final View divider = new View(activity);

            layout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv);

            divider.setBackgroundResource(R.drawable.bg_trans_light_10);

            deviceListView.addView(divider, layout);

        }
        deviceListView.invalidate();
    }

    final String historyNetworks[] = activity.getHistoryFilterNetworks();

    if (historyNetworks != null) {

        for (int i = 0; i < historyNetworks.length; i++) {

            final RelativeLayout singleItemLayout = new RelativeLayout(activity); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item);

            singleItemLayout.setId(i);
            singleItemLayout.setClickable(true);
            singleItemLayout.setBackgroundResource(R.drawable.list_selector);

            singleItemLayout.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

            final TextView itemTitle = new TextView(activity, null, R.style.textMediumLight);
            RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.MATCH_PARENT);
            layout.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            layout.addRule(RelativeLayout.CENTER_VERTICAL);

            // itemTitle.setLayoutParams(layout);
            itemTitle.setGravity(Gravity.LEFT);
            itemTitle.setPadding(leftRightItem, 0, leftRightItem, 0);
            itemTitle.setText(historyNetworks[i]);

            singleItemLayout.addView(itemTitle, layout);

            final CheckBox itemCheck = new CheckBox(activity);

            layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            layout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            layout.addRule(RelativeLayout.CENTER_VERTICAL);

            // itemCheck.setLayoutParams(layout);

            itemCheck.setGravity(Gravity.RIGHT);
            itemCheck.setPadding(leftRightItem, 0, leftRightItem, 0);
            itemCheck.setOnClickListener(null);
            itemCheck.setClickable(false);
            itemCheck.setId(i + historyNetworks.length);

            if (networksToShow.isEmpty() || networksToShow.contains(historyNetworks[i]))
                itemCheck.setChecked(true);
            else
                itemCheck.setChecked(false);

            singleItemLayout.addView(itemCheck, layout);

            singleItemLayout.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(final View v) {
                    final CheckBox check = (CheckBox) v.findViewById(v.getId() + historyNetworks.length);
                    if (check.isChecked()) {
                        check.setChecked(false);
                        networksToShow.remove(historyNetworks[v.getId()]);
                    } else {
                        check.setChecked(true);
                        networksToShow.add(historyNetworks[v.getId()]);
                    }
                    System.out.println(networksToShow.toString());
                }

            });

            networkListView.addView(singleItemLayout);

            final View divider = new View(activity);

            layout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv);

            divider.setBackgroundResource(R.drawable.bg_trans_light_10);

            networkListView.addView(divider, layout);

        }
        networkListView.invalidate();
    }
    /*
     * // Set option as Multiple Choice. So that user can able to select
     * more the one option from list deviceListView.setAdapter(new
     * ArrayAdapter<String>(activity,
     * android.R.layout.simple_list_item_multiple_choice, historyDevices));
     * deviceListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
     * 
     * for (int i = 0; i < historyDevices.length; i++) {
     * //deviceListView.setItemChecked(i, true); }
     * 
     * deviceListView.setOnItemClickListener(new OnItemClickListener() {
     * 
     * @Override public void onItemClick(AdapterView<?> l, View v, int
     * position, long id) {
     * 
     * }
     * 
     * });
     * 
     * 
     * // Set option as Multiple Choice. So that user can able to select
     * more the one option from list networkListView.setAdapter(new
     * ArrayAdapter<String>(activity,
     * android.R.layout.simple_list_item_multiple_choice, networkDevices));
     * networkListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
     * 
     * for (int i = 0; i < networkDevices.length; i++) {
     * networkListView.setItemChecked(i, true); }
     * 
     * SparseBooleanArray checked =
     * deviceListView.getCheckedItemPositions(); ArrayList<String>
     * devicesToShow = new ArrayList<String>(); for(int i = 0; i <
     * checked.size()+1; i++){ if(checked.get(i))
     * devicesToShow.add(historyDevices[i]); }
     */

    return view;
}