Wednesday, February 25, 2015

Dynamic textview on the Android Actionbar


Dynamic textview on the android action bar
1.Use the following inside onCreateOptionsMenu in main activity
2.Replace the strPersonName with your own text.

// creating dynamic textview to display user name on actionbar
  TextView tv = new TextView(this);
  tv.setText(strPersonName);
  tv.setTextColor(getResources().getColor(R.color.white));
  tv.setPadding(5, 0, 5, 0);
  tv.setTypeface(null, Typeface.BOLD);
  tv.setTextSize(14);

  menu.add(0, FILTER_ID, 1, strPersonName).setActionView(tv)
    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

No comments:

Post a Comment