protected void setRightButtonText(String text) { RelativeLayout rightView = (RelativeLayout) findViewById(R.id.right_view); rightView.removeAllViews(); int padding = dp2px(6); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); lp.setMargins(0, 0, dp2px(8), 0); TextView tv = new TextView(this); tv.setText(text); tv.setTextColor(0xFF666666); tv.setTextSize(16.f); tv.setLayoutParams(lp); tv.setBackgroundResource(R.drawable.btn_gray); tv.setPadding(2 * padding, padding, 2 * padding, padding); tv.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { onRightButtonClicked(v); } }); rightView.addView(tv); rightView.setVisibility(View.VISIBLE); }