Skip to content

Commit a48c9d1

Browse files
author
TutorialsAndroid
committed
ADDED SETTING OF TITLE TEXT SIZE AND NOW LINKS ARE CLICKABLE
1 parent 7c0fb09 commit a48c9d1

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

.idea/workspace.xml

Lines changed: 16 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library/src/main/java/com/developer/kalert/KAlertDialog.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.os.Bundle;
88

99
import android.text.Html;
10+
import android.text.util.Linkify;
1011
import android.util.TypedValue;
1112

1213
import android.view.View;
@@ -44,6 +45,7 @@ public class KAlertDialog extends AlertDialog implements View.OnClickListener {
4445

4546
private boolean mShowCancel, mShowContent, mShowTitleText, mCloseFromCancel, mShowConfirm;
4647
private int contentTextSize = 0;
48+
private int titleTextSize = 0;
4749

4850
private FrameLayout mErrorFrame, mSuccessFrame, mProgressFrame, mWarningFrame;
4951

@@ -195,7 +197,7 @@ private void changeAlertType(int alertType, boolean fromCreate) {
195197
setConfirmButtonColor(mColor);
196198
break;
197199
case CUSTOM_IMAGE_TYPE:
198-
setCustomImage(mCustomImgDrawable);
200+
setCustomImage1(mCustomImgDrawable);
199201
setConfirmButtonColor(mColor);
200202
break;
201203
case PROGRESS_TYPE:
@@ -223,6 +225,9 @@ public KAlertDialog setTitleText(String text) {
223225
mTitleText = text;
224226
if (mTitleTextView != null && mTitleText != null) {
225227
showTitleText();
228+
if (titleTextSize != 0) {
229+
mTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, spToPx(titleTextSize, getContext()));
230+
}
226231
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
227232
mTitleTextView.setText(Html.fromHtml(mTitleText,1));
228233
}else {
@@ -236,18 +241,19 @@ private void showTitleText() {
236241
mShowTitleText = true;
237242
if (mTitleTextView != null) {
238243
mTitleTextView.setVisibility(View.VISIBLE);
244+
mContentTextView.setAutoLinkMask(Linkify.ALL);
239245
}
240246
}
241247

242248
public KAlertDialog setCustomImage(int resourceId, Context context) {
243249
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
244-
return setCustomImage(getContext().getResources().getDrawable(resourceId,context.getTheme()));
250+
return setCustomImage1(getContext().getResources().getDrawable(resourceId,context.getTheme()));
245251
} else {
246-
return setCustomImage(getContext().getResources().getDrawable(resourceId));
252+
return setCustomImage1(getContext().getResources().getDrawable(resourceId));
247253
}
248254
}
249255

250-
public KAlertDialog setCustomImage(Drawable drawable) {
256+
private KAlertDialog setCustomImage1(Drawable drawable) {
251257
mCustomImgDrawable = drawable;
252258
if (mCustomImage != null && mCustomImgDrawable != null) {
253259
mCustomImage.setVisibility(View.VISIBLE);
@@ -264,7 +270,7 @@ public KAlertDialog setContentText(String text) {
264270
mContentTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, spToPx(contentTextSize, getContext()));
265271
}
266272
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
267-
mContentTextView.setText(Html.fromHtml(mContentText,1));
273+
mContentTextView.setText(Html.fromHtml(mContentText,0));
268274
}else {
269275
mContentTextView.setText(Html.fromHtml(mContentText));
270276
}
@@ -293,6 +299,7 @@ private void showContentText () {
293299
mShowContent = true;
294300
if (mContentTextView != null) {
295301
mContentTextView.setVisibility(View.VISIBLE);
302+
mContentTextView.setAutoLinkMask(Linkify.ALL);
296303
}
297304
}
298305

@@ -424,6 +431,15 @@ public KAlertDialog cancelButtonColor (int color, Context context){
424431
}
425432
}
426433

434+
public KAlertDialog setTitleTextSize(int value){
435+
this.titleTextSize = value;
436+
return this;
437+
}
438+
439+
public int getTitleTextSize() {
440+
return titleTextSize;
441+
}
442+
427443
public KAlertDialog setContentTextSize ( int value){
428444
this.contentTextSize = value;
429445
return this;

sample/src/main/java/com/developer/kalert/alert/SampleActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void onClick(View v) {
4848
case R.id.under_text_test:
4949
new KAlertDialog(this)
5050
.setTitleText("Title Text")
51-
.setContentText("It's pretty, isn't it?")
51+
.setContentText("Hello")
5252
.setConfirmText("Ok")
5353
.show();
5454

0 commit comments

Comments
 (0)