Skip to content

Commit d9eaba8

Browse files
committed
User can now set the Fragment title and body text colors
1 parent d634fbb commit d9eaba8

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

onboarder/src/main/java/com/jrejaud/onboarder/OnboardingFragment.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ public class OnboardingFragment extends Fragment implements Serializable {
1919

2020
// the fragment initialization parameters
2121
private static final String TITLE = "TITLE";
22+
private final static String TITLE_TEXT_COLOR = "TITLE_TEXT_COLOR";
2223
private static final String BODY_TEXT = "BODY_TEXT";
24+
private final static String BODY_TEXT_COLOR = "TITLE_TEXT_COLOR";
2325
private static final String IMAGE_RESOURCE_ID = "IMAGE_RESOURCE_ID";
2426
private static final String POSITION = "POSITION";
2527
private static final String BUTTON_TEXT = "BUTTON_TEXT";
26-
public final static String BUTTON_BACKGROUND_COLOR = "BUTTON_BACKGROUND_COLOR";
2728

2829
public OnboardingFragment() {
2930
// Required empty public constructor
@@ -37,6 +38,8 @@ public static OnboardingFragment newInstance(OnboardingPage onboardingPage, int
3738
args.putInt(IMAGE_RESOURCE_ID, onboardingPage.getImageResId());
3839
args.putInt(POSITION, position);
3940
args.putString(BUTTON_TEXT, onboardingPage.getButtonText());
41+
args.putInt(TITLE_TEXT_COLOR, onboardingPage.getTitleTextColor());
42+
args.putInt(BODY_TEXT_COLOR,onboardingPage.getBodyTextColor());
4043
fragment.setArguments(args);
4144
return fragment;
4245
}
@@ -60,6 +63,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
6063
/* The button text (if the user set any) */
6164
String buttonText = bundle.getString(BUTTON_TEXT, null);
6265

66+
@ColorRes int titleTextColor = bundle.getInt(TITLE_TEXT_COLOR, -1);
67+
@ColorRes int bodyTextColor = bundle.getInt(BODY_TEXT_COLOR,-1);
68+
6369
TextView titleTextView = (TextView) view.findViewById(R.id.onboarding_fragment_title);
6470
TextView bodyTextView = (TextView) view.findViewById(R.id.onboarding_fragment_body_text);
6571
ImageView imageView = (ImageView) view.findViewById(R.id.onboarding_fragment_image);
@@ -68,13 +74,21 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
6874
//Set the title
6975
if (title !=null) {
7076
titleTextView.setText(title);
77+
//Set the body text color
78+
if (titleTextColor!=-1) {
79+
titleTextView.setTextColor(getResources().getColor(titleTextColor));
80+
}
7181
} else {
7282
titleTextView.setVisibility(View.GONE);
7383
}
7484

7585
//Set the body text
7686
if (bodyText !=null) {
7787
bodyTextView.setText(bodyText);
88+
//Set the body text color
89+
if (bodyTextColor!=-1) {
90+
bodyTextView.setTextColor(getResources().getColor(bodyTextColor));
91+
}
7892
} else {
7993
bodyTextView.setVisibility(View.GONE);
8094
}

onboarder/src/main/java/com/jrejaud/onboarder/OnboardingPage.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
*/
1212
public class OnboardingPage implements Serializable {
1313
private String title;
14+
private @ColorRes int titleTextColor = -1;
1415
private String bodyText;
16+
private @ColorRes int bodyTextColor = -1;
1517
private @DrawableRes
1618
int imageResId = -1;
1719

1820
private String buttonText = null;
1921

20-
2122
public String getTitle() {
2223
return title;
2324
}
@@ -34,6 +35,23 @@ public String getButtonText() {
3435
return buttonText;
3536
}
3637

38+
public int getTitleTextColor() {
39+
return titleTextColor;
40+
}
41+
42+
public void setTitleTextColor(int titleTextColor) {
43+
this.titleTextColor = titleTextColor;
44+
}
45+
46+
public int getBodyTextColor() {
47+
return bodyTextColor;
48+
}
49+
50+
public void setBodyTextColor(int bodyTextColor) {
51+
this.bodyTextColor = bodyTextColor;
52+
}
53+
54+
3755

3856
public OnboardingPage(@Nullable String title,@Nullable String bodyText) {
3957
this.title = title;

0 commit comments

Comments
 (0)