Skip to content

Instantly share code, notes, and snippets.

@ramseth001
Created August 29, 2018 02:29
Show Gist options
  • Save ramseth001/fdc2bbcc3846e8b078afe9b93044045d to your computer and use it in GitHub Desktop.
Save ramseth001/fdc2bbcc3846e8b078afe9b93044045d to your computer and use it in GitHub Desktop.
Create TextView programmatically
/**
* This function customizes the header of the tab
*
* @param tabName Name of the tab
* @return TextView -> header of the tab
*/
private TextView getTabHeader(int tabName) {
TextView textView = new TextView(this);
textView.setText(tabName);
textView.setGravity(Gravity.CENTER);
textView.setTextColor(getResources().getColor(R.color.colorText));
Typeface face;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
face = getResources().getFont(R.font.karla);
} else {
face = ResourcesCompat.getFont(getApplicationContext(), R.font.karla);
}
textView.setTypeface(face);
textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen._16sp));
return textView;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment