List of usage examples for android.widget TextView setTextColor
@android.view.RemotableViewMethod public void setTextColor(ColorStateList colors)
From source file:br.org.funcate.dynamicforms.views.GSketchView.java
/** * @param noteId the id of the note this image belows to. * @param fragmentDetail the fragment detail to use. * @param attrs attributes. * @param requestCode the code for starting the activity with result. * @param parentView parent//from w w w . j a va2s . c o m * @param label label * @param value value * @param constraintDescription constraints */ public GSketchView(final long noteId, final FragmentDetail fragmentDetail, AttributeSet attrs, final int requestCode, LinearLayout parentView, String label, String value, String constraintDescription) { super(fragmentDetail.getActivity(), attrs); this.noteId = noteId; _value = value; final FragmentActivity activity = fragmentDetail.getActivity(); LinearLayout textLayout = new LinearLayout(activity); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(activity); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(activity.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); final Button button = new Button(activity); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); button.setText(R.string.draw_sketch); textLayout.addView(button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); double[] gpsLocation = PositionUtilities.getGpsLocationFromPreferences(preferences); Date currentDate = new Date(); String sketchImageName = ImageUtilities.getSketchImageName(currentDate); File tempDir = ResourcesManager.getInstance(getContext()).getTempDir(); File sketchFile = new File(tempDir, sketchImageName); /* * open markers for new sketch */ MarkersUtilities.launch(fragmentDetail, sketchFile, gpsLocation, requestCode); } catch (Exception e) { //GPLog.error(this, null, e); Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } } }); ScrollView scrollView = new ScrollView(activity); ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, 150); scrollView.setLayoutParams(scrollLayoutParams); parentView.addView(scrollView); imageLayout = new LinearLayout(activity); LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); imageLayout.setLayoutParams(imageLayoutParams); // imageLayout.setMinimumHeight(200); imageLayout.setOrientation(LinearLayout.HORIZONTAL); scrollView.addView(imageLayout); // scrollView.setFillViewport(true); try { refresh(activity); } catch (Exception e) { //GPLog.error(this, null, e); Toast.makeText(this.getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } }
From source file:com.cmax.bodysheild.widget.PagerSlidingTabStripExtends.java
public void setAllTabTextColor(int res) { for (int i = 0; i < tabCount; i++) { View v = tabsContainer.getChildAt(i); if (v instanceof TextView) { TextView tv = (TextView) v; tv.setTextColor(res); tv.setClickable(true);/* w ww .j a va 2s. c o m*/ tv.setEnabled(true); tv.setFocusable(true); } } }
From source file:key.secretkey.MainActivity.java
public void onResume() { super.onResume(); // do not attempt to checkLocalRepository() if no storage permission: immediate crash if (settings.getBoolean("git_external", false)) { if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.READ_EXTERNAL_STORAGE)) { Snackbar snack = Snackbar.make(findViewById(R.id.main_layout), "The store is on the sdcard but the app does not have permission to access it. Please give permission.", Snackbar.LENGTH_INDEFINITE).setAction(R.string.dialog_ok, new View.OnClickListener() { @Override public void onClick(View view) { ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_EXTERNAL_STORAGE); }/*from w w w. j a va2 s.co m*/ }); snack.show(); View view = snack.getView(); TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text); tv.setTextColor(Color.WHITE); tv.setMaxLines(10); } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_EXTERNAL_STORAGE); } } else { checkLocalRepository(); } } else { checkLocalRepository(); } }
From source file:com.example.android.rowanparkingpass.Activities.PassActivity.java
public void setVehicleView() { View vehicleView = findViewById(R.id.vehicle_view); vehicleView.setOnClickListener(new View.OnClickListener() { @Override//w ww . j a v a 2 s . com public void onClick(View v) { Intent intent = new Intent(PassActivity.this, VehiclesActivity.class); intent.putExtra(MODE, mode.UPDATE_PASS_VEHICLE.name()); intent.putExtra("Driver", (Serializable) driver); startActivity(intent); finish(); } }); vehicleView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent = new Intent(PassActivity.this, CreateVehicleActivity.class); intent.putExtra(MODE, mode.UPDATE_PASS_VEHICLE.name()); intent.putExtra("Driver", (Serializable) driver); intent.putExtra("Vehicle", (Serializable) vehicle); startActivity(intent); finish(); return true; } }); // Set up text views for vehicle info TextView newVehicle = (TextView) findViewById(R.id.new_vehicle_text_view); TextView carText = (TextView) findViewById(R.id.car_text_view); TextView plateText = (TextView) findViewById(R.id.plate_text_view); TextView carColor = (TextView) findViewById(R.id.car_color); newVehicle.setText(""); carText.setText(vehicle.getYear() + " " + vehicle.getMake() + " " + vehicle.getModel()); plateText.setText(vehicle.getVehicleState() + " " + vehicle.getLicensePlate()); carColor.setText(""); carColor.setTextColor(Integer.parseInt(vehicle.getColor())); carColor.setBackgroundColor(Integer.parseInt(vehicle.getColor())); }
From source file:com.alexcruz.papuhwalls.Credits.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.credits, null); this.Preferences = new Preferences(getContext()); context = getActivity();/* w ww. j av a2s . co m*/ ActionBar toolbar = ((ActionBarActivity) context).getSupportActionBar(); toolbar.setTitle(R.string.section_aboutapp); //Credits TextView credit_title = (TextView) root.findViewById(R.id.credit_title); credit_title.setTextColor(Preferences.PrimaryText()); TextView credit_desc = (TextView) root.findViewById(R.id.credit_desc); credit_desc.setText(Html.fromHtml(getString(R.string.credit_desc))); credit_desc.setTextColor(Preferences.SecondaryText()); //Free and open source text TextView freeandopensource_text = (TextView) root.findViewById(R.id.freeandopensource_text); freeandopensource_text.setTextColor(Preferences.PrimaryText()); //Library number two TextView libtwo_title = (TextView) root.findViewById(R.id.libtwo_title); libtwo_title.setTextColor(Preferences.PrimaryText()); TextView libtwo_content = (TextView) root.findViewById(R.id.libtwo_content); libtwo_content.setText(Html.fromHtml(getString(R.string.fab_desc))); libtwo_content.setTextColor(Preferences.SecondaryText()); TextView libtwo_license = (TextView) root.findViewById(R.id.libtwo_license); libtwo_license.setTextColor(Preferences.PrimaryText()); TextView libtwo_author = (TextView) root.findViewById(R.id.libtwo_author); libtwo_author.setTextColor(Preferences.SecondaryText()); //Library number three TextView libthree_title = (TextView) root.findViewById(R.id.libthree_title); libthree_title.setTextColor(Preferences.PrimaryText()); TextView libthree_content = (TextView) root.findViewById(R.id.libthree_content); libthree_content.setText(Html.fromHtml(getString(R.string.materialdialogs_desc))); libthree_content.setTextColor(Preferences.SecondaryText()); TextView libthree_license = (TextView) root.findViewById(R.id.libthree_license); libthree_license.setTextColor(Preferences.PrimaryText()); TextView libthree_author = (TextView) root.findViewById(R.id.libthree_author); libthree_author.setTextColor(Preferences.SecondaryText()); //Library number four TextView libfour_title = (TextView) root.findViewById(R.id.libfour_title); libfour_title.setTextColor(Preferences.PrimaryText()); TextView libfour_content = (TextView) root.findViewById(R.id.libfour_content); libfour_content.setText(Html.fromHtml(getString(R.string.materialdrawer_desc))); libfour_content.setTextColor(Preferences.SecondaryText()); TextView libfour_license = (TextView) root.findViewById(R.id.libfour_license); libfour_license.setTextColor(Preferences.PrimaryText()); TextView libfour_author = (TextView) root.findViewById(R.id.libfour_author); libfour_author.setTextColor(Preferences.SecondaryText()); //Library number five TextView libfive_title = (TextView) root.findViewById(R.id.libfive_title); libfive_title.setTextColor(Preferences.PrimaryText()); TextView libfive_content = (TextView) root.findViewById(R.id.libfive_content); libfive_content.setText(Html.fromHtml(getString(R.string.picasso_desc))); libfive_content.setTextColor(Preferences.SecondaryText()); TextView libfive_license = (TextView) root.findViewById(R.id.libfive_license); libfive_license.setTextColor(Preferences.PrimaryText()); TextView libfive_author = (TextView) root.findViewById(R.id.libfive_author); libfive_author.setTextColor(Preferences.SecondaryText()); //Library number six TextView libsix_title = (TextView) root.findViewById(R.id.libsix_title); libsix_title.setTextColor(Preferences.PrimaryText()); TextView libsix_content = (TextView) root.findViewById(R.id.libsix_content); libsix_content.setText(Html.fromHtml(getString(R.string.okhttp_desc))); libsix_content.setTextColor(Preferences.SecondaryText()); TextView libsix_license = (TextView) root.findViewById(R.id.libsix_license); libsix_license.setTextColor(Preferences.PrimaryText()); TextView libsix_author = (TextView) root.findViewById(R.id.libsix_author); libsix_author.setTextColor(Preferences.SecondaryText()); //Library number seven TextView libseven_title = (TextView) root.findViewById(R.id.libseven_title); libseven_title.setTextColor(Preferences.PrimaryText()); TextView libseven_content = (TextView) root.findViewById(R.id.libseven_content); libseven_content.setText(Html.fromHtml(getString(R.string.snackbar_desc))); libseven_content.setTextColor(Preferences.SecondaryText()); TextView libseven_license = (TextView) root.findViewById(R.id.libseven_license); libseven_license.setTextColor(Preferences.PrimaryText()); TextView libseven_author = (TextView) root.findViewById(R.id.libseven_author); libseven_author.setTextColor(Preferences.SecondaryText()); //Library number eight TextView libeight_title = (TextView) root.findViewById(R.id.libeight_title); libeight_title.setTextColor(Preferences.PrimaryText()); TextView libeight_content = (TextView) root.findViewById(R.id.libeight_content); libeight_content.setText(Html.fromHtml(getString(R.string.crash_desc))); libeight_content.setTextColor(Preferences.SecondaryText()); TextView libeight_license = (TextView) root.findViewById(R.id.libeight_license); libeight_license.setTextColor(Preferences.PrimaryText()); TextView libeight_author = (TextView) root.findViewById(R.id.libeight_author); libeight_author.setTextColor(Preferences.SecondaryText()); //Library number nine TextView libnine_title = (TextView) root.findViewById(R.id.libnine_title); libnine_title.setTextColor(Preferences.PrimaryText()); TextView libnine_content = (TextView) root.findViewById(R.id.libnine_content); libnine_content.setText(Html.fromHtml(getString(R.string.appintro_desc))); libnine_content.setTextColor(Preferences.SecondaryText()); TextView libnine_license = (TextView) root.findViewById(R.id.libnine_license); libnine_license.setTextColor(Preferences.PrimaryText()); TextView libnine_author = (TextView) root.findViewById(R.id.libnine_author); libnine_author.setTextColor(Preferences.SecondaryText()); //Library number ten TextView libten_title = (TextView) root.findViewById(R.id.libten_title); libten_title.setTextColor(Preferences.PrimaryText()); TextView libten_content = (TextView) root.findViewById(R.id.libten_content); libten_content.setText(Html.fromHtml(getString(R.string.materialripple_desc))); libten_content.setTextColor(Preferences.SecondaryText()); TextView libten_license = (TextView) root.findViewById(R.id.libten_license); libten_license.setTextColor(Preferences.PrimaryText()); TextView libten_author = (TextView) root.findViewById(R.id.libten_author); libten_author.setTextColor(Preferences.SecondaryText()); //Library number eleven TextView libeleven_title = (TextView) root.findViewById(R.id.libeleven_title); libeleven_title.setTextColor(Preferences.PrimaryText()); TextView libeleven_content = (TextView) root.findViewById(R.id.libeleven_content); libeleven_content.setText(Html.fromHtml(getString(R.string.materialpreference_desc))); libeleven_content.setTextColor(Preferences.SecondaryText()); TextView libeleven_license = (TextView) root.findViewById(R.id.libeleven_license); libeleven_license.setTextColor(Preferences.PrimaryText()); TextView libeleven_author = (TextView) root.findViewById(R.id.libeleven_author); libeleven_author.setTextColor(Preferences.SecondaryText()); //Library number twelve TextView libtwelve_title = (TextView) root.findViewById(R.id.libtwelve_title); libtwelve_title.setTextColor(Preferences.PrimaryText()); TextView libtwelve_content = (TextView) root.findViewById(R.id.libtwelve_content); libtwelve_content.setText(Html.fromHtml(getString(R.string.licensesdialog_desc))); libtwelve_content.setTextColor(Preferences.SecondaryText()); TextView libtwelve_license = (TextView) root.findViewById(R.id.libtwelve_license); libtwelve_license.setTextColor(Preferences.PrimaryText()); TextView libtwelve_author = (TextView) root.findViewById(R.id.libtwelve_author); libtwelve_author.setTextColor(Preferences.SecondaryText()); //Library source buttons TextView credit = (TextView) root.findViewById(R.id.github_button); credit.setTextColor(Preferences.Accent()); credit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent credit = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.jahir_link))); startActivity(credit); } }); TextView fab_web = (TextView) root.findViewById(R.id.floating_github_button); fab_web.setTextColor(Preferences.Accent()); fab_web.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent fab_web = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.fab_web))); startActivity(fab_web); } }); TextView materialdialogs_web = (TextView) root.findViewById(R.id.dialogs_github_button); materialdialogs_web.setTextColor(Preferences.Accent()); materialdialogs_web.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent materialdialogs_web = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.materialdialogs_web))); startActivity(materialdialogs_web); } }); TextView materialdrawer_web = (TextView) root.findViewById(R.id.materialdrawer_github_button); materialdrawer_web.setTextColor(Preferences.Accent()); materialdrawer_web.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent materialdrawer_web = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.materialdrawer_web))); startActivity(materialdrawer_web); } }); TextView picasso_web = (TextView) root.findViewById(R.id.picasso_github_button); picasso_web.setTextColor(Preferences.Accent()); picasso_web.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent picasso_web = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.picasso_web))); startActivity(picasso_web); } }); TextView okhttp_web = (TextView) root.findViewById(R.id.okhttp_github_button); okhttp_web.setTextColor(Preferences.Accent()); okhttp_web.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent okhttp_web = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.okhttp_web))); startActivity(okhttp_web); } }); TextView snackbar_web = (TextView) root.findViewById(R.id.snackbar_github_button); snackbar_web.setTextColor(Preferences.Accent()); snackbar_web.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent snackbar_web = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.snackbar_web))); startActivity(snackbar_web); } }); TextView crash_web = (TextView) root.findViewById(R.id.crash_github_button); crash_web.setTextColor(Preferences.Accent()); crash_web.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent crash_web = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.crash_web))); startActivity(crash_web); } }); TextView appintro_web = (TextView) root.findViewById(R.id.appintro_github_button); appintro_web.setTextColor(Preferences.Accent()); appintro_web.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent appintro_web = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.appintro_web))); startActivity(appintro_web); } }); TextView materialripple_web = (TextView) root.findViewById(R.id.materialripple_github_button); materialripple_web.setTextColor(Preferences.Accent()); materialripple_web.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent materialripple_web = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.materialripple_web))); startActivity(materialripple_web); } }); TextView materialpreference_web = (TextView) root.findViewById(R.id.materialpreference_github_button); materialpreference_web.setTextColor(Preferences.Accent()); materialpreference_web.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent materialpreference_web = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.materialpreference_web))); startActivity(materialpreference_web); } }); TextView licensesdialog_web = (TextView) root.findViewById(R.id.licensesdialog_github_button); licensesdialog_web.setTextColor(Preferences.Accent()); licensesdialog_web.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent licensesdialog_web = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.licensesdialog_web))); startActivity(licensesdialog_web); } }); return root; }
From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java
private TextView createErrorView(String key) { TextView ret = new TextView(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);// w ww. j a v a 2 s. c om params.topMargin = 10; params.bottomMargin = 10; ret.setLayoutParams(params); ret.setTextColor(Color.RED); ret.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10); HashMap<String, String> errors = mAccount.getErrors(); if (errors != null && errors.containsKey(key)) { ret.setText(errors.get(key)); ret.setVisibility(View.VISIBLE); } else { ret.setVisibility(View.INVISIBLE); } return ret; }
From source file:ar.com.xpasta.Controls.PagerSlidingTabStrip.java
private void updateTabStyles() { for (int i = 0; i < tabCount; i++) { View v = tabsContainer.getChildAt(i); v.setBackgroundResource(tabBackgroundResId); if (v instanceof TextView) { TextView tab = (TextView) v; tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab.setTypeface(tabTypeface, tabTypefaceStyle); tab.setTextColor(tabTextColor); if (textAllCaps) tab.setAllCaps(true);/*from w w w . j a v a 2s. com*/ } } }
From source file:fr.cph.chicago.activity.StationActivity.java
/** * Draw line/*w ww . j a v a 2s . c o m*/ * * @param eta * the eta */ private final void drawLine3(final Eta eta) { TrainLine line = eta.getRouteName(); Stop stop = eta.getStop(); int line3Padding = (int) getResources().getDimension(R.dimen.activity_station_stops_line3); Integer viewId = mIds.get(line.toString() + "_" + stop.getDirection().toString()); // viewId might be not there if CTA API provide wrong data if (viewId != null) { LinearLayout line3View = (LinearLayout) findViewById(viewId); Integer id = mIds.get(line.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName()); if (id == null) { LinearLayout insideLayout = new LinearLayout(this); insideLayout.setOrientation(LinearLayout.HORIZONTAL); insideLayout.setLayoutParams(mParamsStop); int newId = Util.generateViewId(); insideLayout.setId(newId); mIds.put(line.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName(), newId); TextView stopName = new TextView(this); stopName.setText(eta.getDestName() + ": "); stopName.setTextColor(getResources().getColor(R.color.grey)); stopName.setPadding(line3Padding, 0, 0, 0); insideLayout.addView(stopName); TextView timing = new TextView(this); timing.setText(eta.getTimeLeftDueDelay() + " "); timing.setTextColor(getResources().getColor(R.color.grey)); timing.setLines(1); timing.setEllipsize(TruncateAt.END); insideLayout.addView(timing); line3View.addView(insideLayout); } else { LinearLayout insideLayout = (LinearLayout) findViewById(id); TextView timing = (TextView) insideLayout.getChildAt(1); timing.setText(timing.getText() + eta.getTimeLeftDueDelay() + " "); } line3View.setVisibility(View.VISIBLE); } }
From source file:com.cleanwiz.applock.ui.adapter.MainPagerAdapter.java
@SuppressLint("InflateParams") private View buildLockView() { View view = mInflater.inflate(R.layout.pager_applock, null); ListView listView = (ListView) view.findViewById(R.id.lv_apps); final LockAdapter adapter = new LockAdapter(mContext); View header = mInflater.inflate(R.layout.pager_applock_header, null); final TextView tvSortAlpha = (TextView) header.findViewById(R.id.sort_alpha); final TextView tvSortDefault = (TextView) header.findViewById(R.id.sort_default); final int colorRed = mContext.getResources().getColor(R.color.text_red); final int colorBlack = mContext.getResources().getColor(R.color.md_black_1); View.OnClickListener onSort = new View.OnClickListener() { @Override/*w ww. j a va2 s . co m*/ public void onClick(View v) { switch (v.getId()) { case R.id.sort_alpha: tvSortAlpha.setTextColor(colorRed); tvSortDefault.setTextColor(colorBlack); adapter.onSort(LockAdapter.SORT_ALPHA); break; case R.id.sort_default: tvSortAlpha.setTextColor(colorBlack); tvSortDefault.setTextColor(colorRed); adapter.onSort(LockAdapter.SORT_DEFAULT); break; } } }; tvSortAlpha.setOnClickListener(onSort); tvSortDefault.setOnClickListener(onSort); listView.addHeaderView(header); listView.setAdapter(adapter); return view; }
From source file:com.aniruddhc.acemusic.player.MainActivity.MainActivity.java
/** * Displays the folder fragment's action items. * * @param filePath The file path to set as the ActionBar's title text. * @param inflater The ActionBar's menu inflater. * @param menu The ActionBar menu to work with. * @param showPaste Pass true if the ActionBar is being updated for a copy/move operation. *///from w ww .j a v a2 s. com public void showFolderFragmentActionItems(String filePath, MenuInflater inflater, Menu menu, boolean showPaste) { getMenu().clear(); inflater.inflate(R.menu.files_folders_fragment, menu); getActionBar().setDisplayShowTitleEnabled(false); getActionBar().setDisplayUseLogoEnabled(false); getActionBar().setDisplayShowCustomEnabled(true); getActionBar().setHomeButtonEnabled(true); getActionBar().setLogo(0); getActionBar().setIcon(0); if (showPaste) { //Change the ActionBar's background and show the Paste Here option. menu.findItem(R.id.action_paste).setVisible(true); menu.findItem(R.id.action_cancel).setVisible(true); getActionBar().setBackgroundDrawable( mContext.getResources().getDrawable(R.drawable.cab_background_top_apptheme)); //Change the KitKat system bar color. if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) getWindow().setBackgroundDrawable(new ColorDrawable(0xFF002E3E)); } else { //Hide the Paste Here option and set the default ActionBar background. menu.findItem(R.id.action_paste).setVisible(false); menu.findItem(R.id.action_cancel).setVisible(false); getActionBar().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext)); //Change the KitKat system bar color. if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext)); } LayoutInflater inflator = LayoutInflater.from(this); View view = inflator.inflate(R.layout.custom_actionbar_layout, null); TextView titleText = (TextView) view.findViewById(R.id.custom_actionbar_title); titleText.setText(filePath); titleText.setSelected(true); titleText.setTextColor(0xFFFFFFFF); //Inject the custom view into the ActionBar. getActionBar().setCustomView(view); }