Example usage for android.widget LinearLayout setBackgroundColor

List of usage examples for android.widget LinearLayout setBackgroundColor

Introduction

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

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:Main.java

public static View getTestFragmentView(Activity activity, OnClickListener clickListener) {
    LinearLayout v = new LinearLayout(activity);
    v.setBackgroundColor(Color.BLUE);
    v.setOrientation(LinearLayout.VERTICAL);
    TextView tv1 = new TextView(activity);
    TextView tv2 = new TextView(activity);
    Button b1 = new Button(activity);
    Button b2 = new Button(activity);
    Button b3 = new Button(activity);

    b1.setText("reload 1");
    b2.setText("reload 2");
    b3.setText("reload all");

    b1.setId(1);//  www. j a va  2 s  .  c  o  m
    b2.setId(2);
    b3.setId(3);

    tv1.setId(android.R.id.text1);
    tv2.setId(android.R.id.text2);

    b1.setOnClickListener(clickListener);
    b2.setOnClickListener(clickListener);
    b3.setOnClickListener(clickListener);

    v.addView(tv1);
    v.addView(tv2);
    v.addView(b1);
    v.addView(b2);
    v.addView(b3);

    return v;
}

From source file:com.actionbarsherlock.sample.demos.app.ActionBarActionItemCustomView.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item = menu.add(0, android.R.id.copy, 0, "Test");

    final int twentyDp = (int) (20 * getResources().getDisplayMetrics().density);

    TypedArray a = getTheme().obtainStyledAttributes(R.styleable.SherlockTheme);
    final int abHeight = a.getLayoutDimension(R.styleable.SherlockTheme_abHeight, LayoutParams.FILL_PARENT);
    a.recycle();// w  ww.jav  a  2  s .  co  m

    LinearLayout l = new LinearLayout(this);
    l.setPadding(twentyDp, 0, twentyDp, 20);
    l.setBackgroundColor(0x55FF0000);

    TextView tv = new TextView(this);
    tv.setText("HI!!");
    tv.setGravity(Gravity.CENTER);
    tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, abHeight));
    l.addView(tv);

    l.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(ActionBarActionItemCustomView.this, "Got custom action item click!",
                    Toast.LENGTH_SHORT).show();
        }
    });

    item.setActionView(l);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    return super.onCreateOptionsMenu(menu);
}

From source file:org.blanco.techmun.android.EventosActivity.java

/**
 * It initialises the components of this activity
 *///from w ww. j  a  v a 2  s. c o m
public void initComponents(Intent intent) {
    mesa = (Mesa) intent.getExtras().get("mesa");

    TextView tNombre = (TextView) findViewById(R.id.mesa_header_event_layout_nombre);
    TextView tRepresentante = (TextView) findViewById(R.id.mesa_header_event_layout_responsable);
    tNombre.setText(mesa.getNombre());

    tRepresentante.setText((mesa.getRepresentante() != null) ? mesa.getRepresentante().getNombre() : "");
    TextView tDescripcion = (TextView) findViewById(R.id.mesa_header_event_layout_descripcion);
    tDescripcion.setText((mesa.getDescripcion() != null) ? mesa.getDescripcion() : "");
    String scolor = mesa.getColor();
    int color = Color.parseColor(scolor);
    LinearLayout img = ((LinearLayout) findViewById(R.id.eventos_layout_mesa_bar));
    img.setBackgroundColor(color);

    eventosListFragment = (EventosListFragment) getSupportFragmentManager()
            .findFragmentById(R.id.eventos_layout_eventos_list_fragment);
    Log.i("techmun2011", "fragment loaded");
    eventosListFragment.setMesa(mesa);
}

From source file:pl.wasat.smarthma.adapter.NewsArticleListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Activity activity = (Activity) getContext();
    LayoutInflater inflater = activity.getLayoutInflater();

    convertView = inflater.inflate(R.layout.view_cell_article, null);

    SwipeDetector swipeDetector = new SwipeDetector(convertView, position);
    swipeDetector.setOnClickListener(listener);
    convertView.setOnTouchListener(swipeDetector);

    NewsArticle article = getItem(position);

    TextView textView = (TextView) convertView.findViewById(R.id.article_title_text);
    textView.setText(article.getTitle());

    TextView dateView = (TextView) convertView.findViewById(R.id.article_listing_smallprint);
    String pubDate = article.getPubDate();
    dateView.setText(pubDate);//from w  ww.  ja  v  a2 s .  co  m

    if (article.isRead()) {
        LinearLayout row = (LinearLayout) convertView.findViewById(R.id.view_cell_article_row_background);
        row.setBackgroundColor(ContextCompat.getColor(activity, R.color.row_selected));
    }
    return convertView;
}

From source file:com.example.alexs.tourguide.dcAdapter.java

/**
 * Provides a view for an AdapterView (ListView, GridView, etc.)
 *
 * @param position The position in the list of data that should be displayed in the
 *                 list item view./*from  w  ww  .  j  a v  a2s  .c o  m*/
 * @param convertView The recycled view to populate.
 * @param parent The parent ViewGroup that is used for inflation.
 * @return The View for the position in the AdapterView.
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Check if the existing view is being reused, otherwise inflate the view
    View listItemView = convertView;
    if (listItemView == null) {
        listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
    }

    // Find the TextView for the list text
    LinearLayout backColorView = (LinearLayout) listItemView.findViewById(R.id.listText);
    backColorView.setBackgroundColor(ContextCompat.getColor(getContext(), mColorID));

    // Get the {@link dcAttractions} object located at this position in the list
    dcAttractions currentAttraction = getItem(position);

    // Find the TextView in the list_item.xml layout with the ID version_name
    TextView nameTextView = (TextView) listItemView.findViewById(R.id.attraction_name);
    // Get the version name from the current dcAttractions object and
    // set this text on the name TextView
    nameTextView.setText(currentAttraction.getAttractionName());

    // Find the TextView in the list_item.xml layout with the ID version_number
    TextView summaryTextView = (TextView) listItemView.findViewById(R.id.attraction_summary);
    // Get the version number from the current dcAttractions object and
    // set this text on the number TextView
    summaryTextView.setText(currentAttraction.getAttractionSummary());

    // Find the TextView in the list_item.xml layout with the ID version_number
    TextView addressTextView = (TextView) listItemView.findViewById(R.id.attraction_address);
    // Get the version number from the current dcAttractions object and
    // set this text on the number TextView
    addressTextView.setText(currentAttraction.getAttractionAddress());

    // Find the ImageView in the list_item.xml layout with the ID list_item_icon
    ImageView iconView = (ImageView) listItemView.findViewById(R.id.list_item_icon);
    // Get the image resource ID from the current dcAttractions object and
    // set the image to iconView
    if (currentAttraction.hasImage()) {
        iconView.setImageResource(currentAttraction.getImageResourceId());
    } else {
        iconView.setVisibility(View.GONE);
    }

    // Return the whole list item layout (containing 2 TextViews and an ImageView)
    // so that it can be shown in the ListView
    return listItemView;
}

From source file:au.com.wallaceit.reddinator.SimpleTabsWidget.java

private void insertTab(int index, String text) {

    TabClickListener clickListener = new TabClickListener(index);
    LinearLayout tabContainer = (LinearLayout) inflater.inflate(R.layout.tab, tabWidget, false);
    tabContainer.setOnClickListener(clickListener);

    TextView tabText = (TextView) tabContainer.findViewById(R.id.tab_text);
    tabText.setText(text);/*from  w w w .j a va2s  . co  m*/
    tabText.setTextColor(colors[0]);
    tabItems.add(tabText);

    LinearLayout indicator = (LinearLayout) tabContainer.findViewById(R.id.tab_indicator);
    indicator.setBackgroundColor(colors[1]);
    indicatorItems.add(indicator);

    tabContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1));
    tabWidget.addView(tabContainer);
}

From source file:ru.orangesoftware.financisto.widget.QuickAmountInput.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    Activity activity = getActivity();//from  w w w .  j  a va  2  s  . c  o  m
    LinearLayout layout = new LinearLayout(activity);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setBackgroundColor(ContextCompat.getColor(activity, R.color.calculator_background));

    LinearLayout.LayoutParams lpWrapWrap = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    lpWrapWrap.weight = 1;

    // picker
    Currency currency = CurrencyCache.getCurrencyOrEmpty(currencyId);
    picker = new AmountPicker(activity, currency.decimals);
    layout.addView(picker, lpWrapWrap);
    picker.setCurrent(new BigDecimal(amount));
    picker.setOnChangeListener((picker, oldVal, newVal) -> setTitle());

    // buttons
    LinearLayout buttonsLayout = new LinearLayout(new ContextThemeWrapper(activity, R.style.ButtonBar), null,
            R.style.ButtonBar);
    buttonsLayout.setOrientation(LinearLayout.HORIZONTAL);

    Button bOK = new Button(activity);
    bOK.setText(R.string.ok);
    bOK.setOnClickListener(arg0 -> {
        listener.onAmountChanged(picker.getCurrent().toPlainString());
        dismiss();
    });
    buttonsLayout.addView(bOK, lpWrapWrap);

    Button bClear = new Button(activity);
    bClear.setText(R.string.reset);
    bClear.setOnClickListener(arg0 -> picker.setCurrent(BigDecimal.ZERO));
    buttonsLayout.addView(bClear, lpWrapWrap);

    Button bCancel = new Button(activity);
    bCancel.setText(R.string.cancel);
    bCancel.setOnClickListener(arg0 -> dismiss());

    buttonsLayout.addView(bCancel, lpWrapWrap);
    layout.addView(buttonsLayout,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    return layout;
}

From source file:net.ustyugov.jtalk.activity.XMLConsole.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    service = JTalkService.getInstance();
    setTheme(Colors.isLight ? R.style.AppThemeLight : R.style.AppThemeDark);
    setTitle("XML Console");
    getActionBar().setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.paged_activity);

    LinearLayout linear = (LinearLayout) findViewById(R.id.linear);
    linear.setBackgroundColor(Colors.BACKGROUND);

    LayoutInflater inflater = LayoutInflater.from(this);
    MainPageAdapter adapter = new MainPageAdapter(mPages);

    Cursor cursor = service.getContentResolver().query(JTalkProvider.ACCOUNT_URI, null,
            AccountDbHelper.ENABLED + " = '" + 1 + "'", null, null);
    if (cursor != null && cursor.getCount() > 0) {
        cursor.moveToFirst();/*from  w ww .j  a  v  a 2  s  .co m*/
        do {
            final String account = cursor.getString(cursor.getColumnIndex(AccountDbHelper.JID)).trim();

            View page = inflater.inflate(R.layout.list_activity, null);
            page.setTag(account);
            mPages.add(page);

            ListView list = (ListView) page.findViewById(R.id.list);
            list.setDividerHeight(0);
            list.setCacheColorHint(0x00000000);
        } while (cursor.moveToNext());
        cursor.close();
    }

    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(adapter);
    mPager.setCurrentItem(0);

    TitlePageIndicator mTitleIndicator = (TitlePageIndicator) findViewById(R.id.indicator);
    mTitleIndicator.setTextColor(0xFF555555);
    mTitleIndicator.setViewPager(mPager);
}

From source file:org.akvo.caddisfly.ui.BaseActivity.java

/**
 * Changes the action bar style depending on if the app is in user mode or diagnostic mode
 * This serves as a visual indication as to what mode the app is running in
 *//*  ww  w  .j a v a 2  s.  c  o m*/
void changeActionBarStyleBasedOnCurrentMode() {
    if (AppPreferences.isDiagnosticMode()) {
        if (getSupportActionBar() != null) {
            getSupportActionBar()
                    .setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.diagnostic)));
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.diagnostic_status));
        }
        LinearLayout layoutTitle = (LinearLayout) findViewById(R.id.layoutTitleBar);
        if (layoutTitle != null) {
            layoutTitle.setBackgroundColor(ContextCompat.getColor(this, R.color.diagnostic));
        }

    } else {

        TypedValue typedValue = new TypedValue();
        getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);
        int color = typedValue.data;

        if (getSupportActionBar() != null) {
            getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
        }

        LinearLayout layoutTitle = (LinearLayout) findViewById(R.id.layoutTitleBar);
        if (layoutTitle != null) {
            layoutTitle.setBackgroundColor(color);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
            color = typedValue.data;

            getWindow().setStatusBarColor(color);
        }
    }
}

From source file:com.example.android.tourguide.ObjectAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Check if an existing view is being reused, otherwise inflate the view
    View listItemView = convertView;
    if (listItemView == null) {
        listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
    }/*ww w . jav  a2 s . c o m*/

    // Get the {@link Object} object located at this position in the list
    final Object currentObject = getItem(position);

    // Find the TextView in the list_item.xml layout with the ID name_text_view.
    TextView objectNameTV = (TextView) listItemView.findViewById(R.id.name_text_view);
    objectNameTV.setSelected(true);
    objectNameTV.setText(currentObject.getObjectName());

    // Find the TextView in the list_item.xml layout with the ID address_text_view.
    TextView addressTV = (TextView) listItemView.findViewById(R.id.address_text_view);
    addressTV.setSelected(true);
    addressTV.setText(currentObject.getObjectAddress());

    // Find the TextView in the list_item.xml layout with the ID description_text_view.
    TextView objectDescription = (TextView) listItemView.findViewById(R.id.description_text_view);
    objectDescription.setText(currentObject.getObjectDescription());

    // Find the ImageView in the list_item.xml layout with the ID image.
    final ImageView imageView = (ImageView) listItemView.findViewById(R.id.image);
    // Check if an image is provided for this word or not
    if (currentObject.hasImage()) {
        // If an image is available, display the provided image based on the resource ID
        imageView.setImageResource(currentObject.getImageResourceId());
        // Make sure the view is visible
        imageView.setVisibility(View.VISIBLE);
    } else {
        // Otherwise hide the ImageView (set visibility to GONE)
        imageView.setVisibility(View.GONE);
    }

    LinearLayout textContainer = (LinearLayout) listItemView.findViewById(R.id.text_container);
    int color = ContextCompat.getColor(getContext(), mColorResourceId);
    textContainer.setBackgroundColor(color);

    textContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (currentObject.hasImage()) {
                if (imageView.getVisibility() == View.GONE) {
                    imageView.setVisibility(View.VISIBLE);
                } else {
                    imageView.setVisibility(View.GONE);
                }
            }
        }
    });

    // Return the whole list item layout (containing 2 TextViews) so that it can be shown in
    // the ListView.
    return listItemView;
}