Change text color in TableLayout in markdown. Change markdown TextView style.

This commit is contained in:
Alex Ning 2019-12-30 22:46:45 +08:00
parent a60c249b16
commit 286ab8ebca
6 changed files with 33 additions and 5 deletions

View File

@ -7,17 +7,21 @@ import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Spanned;
import android.text.style.SuperscriptSpan; import android.text.style.SuperscriptSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.util.TypedValue;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -110,6 +114,17 @@ public class ViewSidebarActivity extends BaseActivity {
params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId); params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId);
toolbar.setLayoutParams(params); toolbar.setLayoutParams(params);
} }
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
int dp = 16;
int px = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
dp,
resources.getDisplayMetrics()
);
markdownRecyclerView.setPadding(px, px, px, resources.getDimensionPixelSize(navBarResourceId));
}
} }
String subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); String subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
@ -123,8 +138,14 @@ public class ViewSidebarActivity extends BaseActivity {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
int markdownColor = ContextCompat.getColor(this, R.color.defaultTextColor);
Markwon markwon = Markwon.builder(this) Markwon markwon = Markwon.builder(this)
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@Override
public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
textView.setTextColor(markdownColor);
}
@Override @Override
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
builder.linkResolver((view, link) -> { builder.linkResolver((view, link) -> {

View File

@ -8,6 +8,7 @@ import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.Spanned;
import android.text.style.SuperscriptSpan; import android.text.style.SuperscriptSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.util.TypedValue; import android.util.TypedValue;
@ -136,8 +137,14 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mOauthRetrofit = oauthRetrofit; mOauthRetrofit = oauthRetrofit;
mRedditDataRoomDatabase = redditDataRoomDatabase; mRedditDataRoomDatabase = redditDataRoomDatabase;
mGlide = glide; mGlide = glide;
int markdownColor = ContextCompat.getColor(activity, R.color.defaultTextColor);
mMarkwon = Markwon.builder(mActivity) mMarkwon = Markwon.builder(mActivity)
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@Override
public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
textView.setTextColor(markdownColor);
}
@Override @Override
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
builder.linkResolver((view, link) -> { builder.linkResolver((view, link) -> {

View File

@ -36,8 +36,7 @@
android:id="@+id/markdown_recycler_view_view_sidebar_activity" android:id="@+id/markdown_recycler_view_view_sidebar_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingTop="16dp" android:padding="16dp"
android:paddingBottom="16dp"
android:clipToPadding="false" android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> app:layout_behavior="@string/appbar_scrolling_view_behavior" />

View File

@ -3,6 +3,4 @@
android:id="@+id/text" android:id="@+id/text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:textSize="?attr/content_font_default" /> android:textSize="?attr/content_font_default" />

View File

@ -2,7 +2,8 @@
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="16dp" android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:scrollbarStyle="outsideInset"> android:scrollbarStyle="outsideInset">
<TableLayout <TableLayout

View File

@ -86,6 +86,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:visibility="gone" /> android:visibility="gone" />
<com.nex3z.flowlayout.FlowLayout <com.nex3z.flowlayout.FlowLayout