Skip to content

Commit

Permalink
Merge pull request #1 from davidcode43w/davidcode43w-patch-1
Browse files Browse the repository at this point in the history
Add scroll to custom text
  • Loading branch information
davo417 authored May 18, 2021
2 parents d37422b + 9771da5 commit 88e7b4e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
12 changes: 7 additions & 5 deletions library/src/main/java/cn/pedant/SweetAlert/SweetAlertDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class SweetAlertDialog extends Dialog implements View.OnClickListener {
private Animation mSuccessBowAnim;
private TextView mTitleTextView;
private TextView mContentTextView;
private ScrollView mContentScrollView;
private FrameLayout mCustomViewContainer;
private View mCustomView;
private String mTitleText;
Expand Down Expand Up @@ -190,6 +191,7 @@ protected void onCreate(Bundle savedInstanceState) {
mDialogView = getWindow().getDecorView().findViewById(android.R.id.content);
mTitleTextView = findViewById(R.id.title_text);
mContentTextView = findViewById(R.id.content_text);
mContentScrollView = findViewById(R.id.content_scroll);
mCustomViewContainer = findViewById(R.id.custom_view_container);
mErrorFrame = findViewById(R.id.error_frame);
mErrorX = mErrorFrame.findViewById(R.id.error_x);
Expand Down Expand Up @@ -371,7 +373,7 @@ public SweetAlertDialog setContentText(String text) {
mContentTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, spToPx(contentTextSize, getContext()));
}
mContentTextView.setText(Html.fromHtml(mContentText));
mContentTextView.setVisibility(View.VISIBLE);
mContentScrollView.setVisibility(View.VISIBLE);
mCustomViewContainer.setVisibility(View.GONE);
}
return this;
Expand Down Expand Up @@ -416,8 +418,8 @@ public boolean isShowContentText() {

public SweetAlertDialog showContentText(boolean isShow) {
mShowContent = isShow;
if (mContentTextView != null) {
mContentTextView.setVisibility(mShowContent ? View.VISIBLE : View.GONE);
if (mContentScrollView != null) {
mContentScrollView.setVisibility(mShowContent ? View.VISIBLE : View.GONE);
}
return this;
}
Expand Down Expand Up @@ -645,7 +647,7 @@ public SweetAlertDialog setCustomView(View view) {
if (mCustomView != null && mCustomViewContainer != null) {
mCustomViewContainer.addView(view);
mCustomViewContainer.setVisibility(View.VISIBLE);
mContentTextView.setVisibility(View.GONE);
mContentScrollView.setVisibility(View.GONE);
}
return this;
}
Expand Down Expand Up @@ -717,4 +719,4 @@ private void hideSoftKeyboard() {
}
}
}
}
}
36 changes: 23 additions & 13 deletions library/src/main/res/layout/alert_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,31 @@
tools:visibility="visible" />


<TextView
android:id="@+id/content_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<ScrollView
android:id="@+id/content_scroll"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:maxLines="1000"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textAlignment="center"
android:textColor="?attr/sweet_alert_content_text_color"
android:textSize="16sp"
android:visibility="gone"
tools:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry"
tools:visibility="visible" />
tools:visibility="visible">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">

<TextView
android:id="@+id/content_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:maxLines="100"
android:textColor="?attr/sweet_alert_content_text_color"
android:textSize="16sp"
tools:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry"/>
</FrameLayout>

</ScrollView>

<FrameLayout
android:id="@+id/custom_view_container"
Expand Down

0 comments on commit 88e7b4e

Please sign in to comment.