Skip to content
This repository has been archived by the owner on Dec 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1 from bropane/master
Browse files Browse the repository at this point in the history
Added ability to change text color of title and subtitle programmatically and in xml.
  • Loading branch information
xiprox committed Feb 21, 2015
2 parents 065231d + 4520fb6 commit f202bf8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions library/src/main/java/tr/xip/errorview/ErrorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public class ErrorView extends LinearLayout {
private int errorImageRes;

private String errorTitle;
private int errorTitleColor;

private String errorSubtitle;
private int errorSubtitleColor;

private boolean showTitle;
private boolean showSubtitle;
Expand Down Expand Up @@ -84,7 +87,11 @@ private void init() {
try {
errorImageRes = a.getResourceId(R.styleable.ErrorView_ev_errorImage, R.drawable.error_view_cloud);
errorTitle = a.getString(R.styleable.ErrorView_ev_errorTitle);
errorTitleColor = a.getColor(R.styleable.ErrorView_ev_errorTitleColor,
getResources().getColor(R.color.error_view_text));
errorSubtitle = a.getString(R.styleable.ErrorView_ev_errorSubtitle);
errorSubtitleColor = a.getColor(R.styleable.ErrorView_ev_errorSubtitleColor,
getResources().getColor(R.color.error_view_text_light));
showTitle = a.getBoolean(R.styleable.ErrorView_ev_showTitle, true);
showSubtitle = a.getBoolean(R.styleable.ErrorView_ev_showSubtitle, true);
showRetryButton = a.getBoolean(R.styleable.ErrorView_ev_showRetryButton, true);
Expand All @@ -111,6 +118,9 @@ private void init() {
if (!showRetryButton)
mRetryButton.setVisibility(GONE);

mErrorTitle.setTextColor(errorTitleColor);
mErrorSubtitle.setTextColor(errorSubtitleColor);

mRetryButton.setTextColor(retryButtonTextColor);
mRetryButton.setBackgroundResource(retryButtonBackground);
} finally {
Expand Down Expand Up @@ -191,6 +201,15 @@ public void setErrorTitle(int res) {
mErrorTitle.setText(res);
}

/**
* Sets the error title text to a given color.
*
* @param res color resource to use for error title text.
*/
public void setErrorTitleColor(int res){
mErrorTitle.setTextColor(res);
}

/**
* Sets the error subtitle to a given {@link java.lang.String}.
*
Expand All @@ -209,6 +228,14 @@ public void setErrorSubtitle(int res) {
mErrorSubtitle.setText(res);
}

/**
* Sets the error subtitle text to a given color
* @param res color resource to use for error subtitle text.
*/
public void setErrorSubtitleColor(int res){
mErrorSubtitle.setTextColor(res);
}

/**
* Sets the retry button's text to a given {@link java.lang.String}.
*
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<resources>
<declare-styleable name="ErrorView">
<attr name="ev_errorTitle" format="string" />
<attr name="ev_errorTitleColor" format="color" />
<attr name="ev_errorSubtitle" format="string" />
<attr name="ev_errorSubtitleColor" format="color" />
<attr name="ev_errorImage" format="reference" />
<attr name="ev_showTitle" format="boolean" />
<attr name="ev_showSubtitle" format="boolean" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public void onRetry() {

mErrorView.setError(ErrorViewStatusCodes.CODE_408);
mErrorView.setErrorTitle(R.string.error_title_damn);
mErrorView.setErrorTitleColor(getResources().getColor(android.R.color.holo_orange_dark));
mErrorView.setErrorSubtitleColor(getResources().getColor(android.R.color.holo_green_dark));
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:ev_errorSubtitle="@string/error_subtitle_failed_one_more_time"
app:ev_errorTitleColor="@android:color/holo_blue_dark"
app:ev_errorSubtitleColor="@android:color/holo_blue_bright"
app:ev_retryButtonTextColor="@color/apptheme_accent" />
</RelativeLayout>

0 comments on commit f202bf8

Please sign in to comment.