Skip to content

Instantly share code, notes, and snippets.

@voghDev
Last active November 6, 2015 06:45
Show Gist options
  • Select an option

  • Save voghDev/2319cb559d3ba6d097cd to your computer and use it in GitHub Desktop.

Select an option

Save voghDev/2319cb559d3ba6d097cd to your computer and use it in GitHub Desktop.
custom Dialog class that colors the title
package es.voghdev.examples;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import java.util.List;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import butterknife.OnItemSelected;
public class ColoredTitleDialog extends Dialog{
int titleColorResId = Color.GREEN;
public ColoredTitleDialog(Context context, int theme) {
super(context, theme);
init();
}
protected ColoredTitleDialog(Context context, boolean cancelable,
OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
init();
}
public ColoredTitleDialog(Context context) {
super(context);
init();
}
protected void init(){
setTitle(R.string.search);
setContentView( getLayoutId() );
setCancelable(true);
setTitleColors();
}
protected int getLayoutId(){
return R.layout.view_colored_dialog;
}
public void setPositiveButton(int textResId, android.view.View.OnClickListener listener){
button.setText(textResId);
button.setOnClickListener(listener);
}
public void setTitleColor(int resId) {
this.titleColorResId = resId;
setTitleColors();
}
private void setTitleColors() {
int dividerId = getContext().getResources().getIdentifier("android:id/titleDivider", null, null);
int titleId = android.R.id.title;
View divider = findViewById(dividerId);
View title = findViewById(titleId);
if(divider != null)
divider.setBackgroundColor(titleColorResId);
if(title != null && title instanceof TextView)
((TextView)title).setTextColor(titleColorResId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment