Last active
November 6, 2015 06:45
-
-
Save voghDev/2319cb559d3ba6d097cd to your computer and use it in GitHub Desktop.
custom Dialog class that colors the title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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