Example usage for android.widget TextView setBackgroundColor

List of usage examples for android.widget TextView setBackgroundColor

Introduction

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

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:de.devmil.common.ui.color.HistorySelectorView.java

private void makeColorList() {
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout colorlist = (LinearLayout) findViewById(R.id.colorlist);

    if (colors == null || colors.length() <= 0) {
        View nocolors = findViewById(R.id.nocolors);
        nocolors.setVisibility(View.VISIBLE);
        colorlist.setVisibility(View.GONE);
        findViewById(R.id.colorlistscroll).setVisibility(View.GONE); //have to remove it's parent container too
        return;/*from w w  w .j a  va2s  . c om*/
    }
    try {
        for (int i = colors.length() - 1; i >= 0; i--) {
            final int color = colors.getInt(i);
            ViewGroup boxgroup = (ViewGroup) inflater.inflate(R.layout.color_historyview_item, colorlist,
                    false);
            TextView box = (TextView) boxgroup.findViewById(R.id.colorbox);
            box.setBackgroundColor(color);
            //box.setText("#"+Integer.toHexString(color));
            colorlist.addView(boxgroup);
            box.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    setColor(color);
                    onColorChanged();
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.scooter1556.sms.android.presenter.SettingsItemPresenter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT));
    view.setFocusable(true);/*from w  w w  .java  2 s. co  m*/
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ContextCompat.getColor(parent.getContext(), R.color.primary));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}

From source file:eu.trentorise.smartcampus.communicator.custom.MainAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    //View view = null;
    ViewHolder holder = new ViewHolder();

    if (convertView == null) {
        if (position == 0) {
            Integer unread = null;
            holder.view = ((LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE))
                    .inflate(R.layout.tumb_view, null);
            int resource = R.drawable.inbox;
            String txt = null;/*from w  w  w .java 2  s. c  om*/
            if ((unread = CommunicatorHelper.getUnreadCount()) != null) {
                if (unread > 0) {
                    resource = R.drawable.inbox_alert;
                    txt = "" + unread;
                }
            } else {
                new UpdateReadCountTask(holder.view).execute();
            }
            ((TextView) holder.view.findViewById(R.id.numberView)).setText(txt);
            holder.view.findViewById(R.id.containerView).setBackgroundResource(resource);
        } else {
            TextView tmp = new TextView(context);
            tmp.setBackgroundColor(context.getResources().getColor(android.R.color.transparent));
            tmp.setCompoundDrawablesWithIntrinsicBounds(null,
                    context.getResources().getDrawable(ACTIONS[position].thumbnail), null, null);
            tmp.setText(ACTIONS[position].description);
            tmp.setTextColor(context.getResources().getColor(R.color.sc_dark_gray));
            tmp.setGravity(Gravity.CENTER);
            holder.view = tmp;
        }
        holder.view.setOnClickListener(new CommunicatorOnClickListener(position));

    } else {
        holder.view = convertView;
        if (position == 0) {
            Integer unread = null;
            holder.view = ((LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE))
                    .inflate(R.layout.tumb_view, null);
            int resource = R.drawable.inbox;
            String txt = null;
            if ((unread = CommunicatorHelper.getUnreadCount()) != null) {
                if (unread > 0) {
                    resource = R.drawable.inbox_alert;
                    txt = "" + unread;
                }
            } else {
                new UpdateReadCountTask(holder.view).execute();
            }
            ((TextView) holder.view.findViewById(R.id.numberView)).setText(txt);
            holder.view.findViewById(R.id.containerView).setBackgroundResource(resource);
        } else {
            TextView tmp = new TextView(context);
            tmp.setBackgroundColor(context.getResources().getColor(android.R.color.transparent));
            tmp.setCompoundDrawablesWithIntrinsicBounds(null,
                    context.getResources().getDrawable(ACTIONS[position].thumbnail), null, null);
            tmp.setText(ACTIONS[position].description);
            tmp.setTextColor(context.getResources().getColor(R.color.sc_dark_gray));
            tmp.setGravity(Gravity.CENTER);
            holder.view = tmp;
        }
        holder.view.setOnClickListener(new CommunicatorOnClickListener(position));
    }

    return holder.view;
}

From source file:com.scooter1556.sms.androidtv.presenter.MediaFolderPresenter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT));
    view.setFocusable(true);/*from w ww .jav a 2s . c  o m*/
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ContextCompat.getColor(parent.getContext(), R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}

From source file:com.philliphsu.bottomsheetpickers.time.numberpad.NumberPadTimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);

    mInputField = (TextView) view.findViewById(R.id.input_time);
    mNumpad = (NumberPadTimePicker) view.findViewById(R.id.number_grid);

    final FloatingActionButton fab = (FloatingActionButton) mNumpad.findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override//from www  .  j  ava  2  s. co  m
        public void onClick(View v) {
            if (!mNumpad.checkTimeValid())
                return;
            onTimeSet(mNumpad, mNumpad.getHour(), mNumpad.getMinute());
        }
    });

    if (!mThemeSetAtRuntime) {
        mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark);
    }
    mNumpad.setOnInputChangeListener(this);
    mNumpad.insertDigits(mInputtedDigits); // TOneverDO: before mNumpad.setOnInputChangeListener(this);
    mNumpad.setAmPmState(mAmPmState);

    // Prepare colors
    int accentColor = Utils.getThemeAccentColor(getContext());
    int lightGray = ContextCompat.getColor(getContext(), R.color.light_gray);
    int darkGray = ContextCompat.getColor(getContext(), R.color.dark_gray);
    int white = ContextCompat.getColor(getContext(), android.R.color.white);

    // Set background color of entire view
    view.setBackgroundColor(mThemeDark ? darkGray : white);

    TextView inputTime = (TextView) view.findViewById(R.id.input_time);
    inputTime.setBackgroundColor(mThemeDark ? lightGray : accentColor);
    inputTime.setTextColor(ContextCompat.getColor(getContext(), android.R.color.white));

    mNumpad.setTheme(getContext()/*DO NOT GIVE THE APPLICATION CONTEXT, OR ELSE THE NUMPAD
                                 CAN'T GET THE CORRECT ACCENT COLOR*/, mThemeDark);

    return view;
}

From source file:org.cvasilak.jboss.mobile.app.fragments.OperationExecViewFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ActionBar bar = ((ActionBarActivity) getActivity()).getSupportActionBar();
    bar.setTitle(oper.getName());/*from  w ww .j  a va2  s  .c  o  m*/

    MergeAdapter adapter = new MergeAdapter();

    // Section: Attributes
    adapter.addAdapter(new ManagementModelRowAdapter(getActivity(), oper.getParameters(), this));

    // Section: Description
    TextView descrHeader = new TextView(getActivity());
    descrHeader.setBackgroundColor(Color.DKGRAY);
    descrHeader.setPadding(15, 10, 0, 10);
    descrHeader.setText(R.string.description);
    adapter.addView(descrHeader);

    TextView description = new TextView(getActivity());
    description.setText(oper.getDescr());

    adapter.addView(description);

    setListAdapter(adapter);
}

From source file:com.example.inmarsat.hellomap.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    setUpMapIfNeeded();// w w w .  jav  a 2s  . c o  m
    // set the background of the text view showing the data from the API calls
    if (findViewById(R.id.detailsText) != null) {
        TextView view = (TextView) findViewById(R.id.detailsText);
        view.setBackgroundColor(Color.BLACK);
        view.setTextColor(Color.WHITE);
    }
}

From source file:org.cvasilak.jboss.mobile.app.fragments.ConfigurationViewFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ActionBar bar = ((ActionBarActivity) getActivity()).getSupportActionBar();
    bar.setTitle(getString(R.string.configuration));

    MergeAdapter adapter = new MergeAdapter();

    TextView sectionHeader;

    // Section: Server Information
    sectionHeader = new TextView(getActivity());
    sectionHeader.setBackgroundColor(Color.DKGRAY);
    sectionHeader.setPadding(15, 10, 0, 10);
    sectionHeader.setText("Server Information");
    adapter.addView(sectionHeader);//w w  w. j ava2  s .c  o  m

    MetricsAdapter confMetricsAdapter = new MetricsAdapter(getActivity(), confMetrics);
    adapter.addAdapter(confMetricsAdapter);

    // Section: Server Configuration
    sectionHeader = new TextView(getActivity());
    sectionHeader.setBackgroundColor(Color.DKGRAY);
    sectionHeader.setPadding(15, 10, 0, 10);
    sectionHeader.setText("Server Configuration");
    adapter.addView(sectionHeader);
    adapter.addAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,
            new String[] { "Extensions", "Properties" }));

    setListAdapter(adapter);
}

From source file:net.mm2d.dmsexplorer.ServerDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.frg_server_detail, container, false);
    final String udn = getArguments().getString(Const.EXTRA_UDN);
    final DataHolder dataHolder = DataHolder.getInstance();
    final MediaServer server = dataHolder.getMsControlPoint().getMediaServer(udn);
    if (server == null) {
        getActivity().finish();/*  w w  w .jav  a 2s . c  om*/
        return rootView;
    }
    final TextView titleView = (TextView) rootView.findViewById(R.id.title);
    if (titleView != null) {
        titleView.setText(server.getFriendlyName());
        titleView.setBackgroundColor(ThemeUtils.getAccentColor(server.getFriendlyName()));
    }
    final RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.server_detail);
    final PropertyAdapter adapter = new PropertyAdapter(getContext());
    setupPropertyAdapter(adapter, server);
    adapter.setOnItemLinkClickListener(this);
    recyclerView.setAdapter(adapter);

    FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    if (fab == null) {
        fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
    }
    if (fab != null) {
        fab.setOnClickListener(view -> {
            final Intent intent = CdsListActivity.makeIntent(getContext(), udn);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                final TransitionSet ts = new TransitionSet();
                ts.addTransition(new Slide(Gravity.START));
                ts.addTransition(new Fade());
                getActivity().getWindow().setExitTransition(ts);
                startActivity(intent,
                        ActivityOptions.makeSceneTransitionAnimation(getActivity(), view, "share").toBundle());
            } else {
                startActivity(intent);
            }
        });
    }
    return rootView;
}

From source file:com.itime.team.itime.fragments.InputDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    // Get the layout inflater
    final LayoutInflater inflater = getActivity().getLayoutInflater();

    TextView title = new TextView(getActivity());
    // You Can Customise your Title here
    String titleText = getArguments().getString(INPUT_DIALOG_TITLE);
    title.setText(titleText);/*from  w  w  w.j  av a 2  s  . c om*/
    title.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
    title.setPadding(10, 10, 10, 10);
    title.setGravity(Gravity.CENTER);
    title.setTextColor(Color.WHITE);
    title.setTextSize(20);

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(inflater.inflate(R.layout.fragment_input_dialog, null)).setCustomTitle(title)
            // Add action buttons
            .setPositiveButton(R.string.Save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    TextView inputArea = (TextView) getDialog().findViewById(R.id.input_area);
                    mListener.onDialogPositiveClick(inputArea.getText().toString());

                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    mListener.onDialogNegativeClick(InputDialogFragment.this);
                }
            });
    return builder.create();
}