feat: 用户界面性别显示
This commit is contained in:
parent
b7cdcb09cb
commit
dd25cd3c21
|
|
@ -62,6 +62,9 @@ class UserActivity : BaseActivity() {
|
|||
@BindView(R.id.user_center_stat_fans)
|
||||
lateinit var fansStatTv: TextView
|
||||
|
||||
@BindView(R.id.user_sex)
|
||||
lateinit var sexTv: TextView
|
||||
|
||||
@BindView(R.id.user_center_action_btn)
|
||||
lateinit var actionBtn: TintMaterialButton
|
||||
|
||||
|
|
@ -169,6 +172,7 @@ class UserActivity : BaseActivity() {
|
|||
actionBtn.setText(R.string.button_follow)
|
||||
}
|
||||
}
|
||||
sexTv.text = if (profileBean!!.user!!.sex == "1") "♂" else if (profileBean!!.user!!.sex == "2") "♀" else "?"
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
package com.huanchengfly.tieba.post.widgets.theme;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.huanchengfly.tieba.post.R;
|
||||
import com.huanchengfly.tieba.post.interfaces.BackgroundTintable;
|
||||
import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable;
|
||||
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
|
||||
|
||||
@SuppressLint("CustomViewStyleable")
|
||||
public class TintFrameLayout extends FrameLayout implements Tintable, BackgroundTintable {
|
||||
private int mBackgroundTintResId;
|
||||
|
||||
public TintFrameLayout(@NonNull Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public TintFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public TintFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
if (isInEditMode()) {
|
||||
return;
|
||||
}
|
||||
if (attrs == null) {
|
||||
mBackgroundTintResId = 0;
|
||||
applyTintColor();
|
||||
return;
|
||||
}
|
||||
TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.TintView, defStyleAttr, 0);
|
||||
mBackgroundTintResId = array.getResourceId(R.styleable.TintView_backgroundTint, 0);
|
||||
array.recycle();
|
||||
applyTintColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tint() {
|
||||
applyTintColor();
|
||||
}
|
||||
|
||||
private void applyTintColor() {
|
||||
if (mBackgroundTintResId != 0) {
|
||||
if (getBackground() == null) {
|
||||
setBackgroundColor(ThemeUtils.getColorById(getContext(), mBackgroundTintResId));
|
||||
} else {
|
||||
setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.getColorById(getContext(), mBackgroundTintResId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackgroundTintResId(int resId) {
|
||||
mBackgroundTintResId = resId;
|
||||
tint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBackgroundTintResId() {
|
||||
return mBackgroundTintResId;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.huanchengfly.tieba.post.widgets.theme
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import android.widget.FrameLayout
|
||||
import com.huanchengfly.tieba.post.R
|
||||
import com.huanchengfly.tieba.post.getColorStateListCompat
|
||||
import com.huanchengfly.tieba.post.interfaces.BackgroundTintable
|
||||
import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable
|
||||
import com.huanchengfly.tieba.post.ui.theme.utils.ColorStateListUtils
|
||||
|
||||
@SuppressLint("CustomViewStyleable")
|
||||
class TintFrameLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr), Tintable, BackgroundTintable {
|
||||
var backgroundTintRes: Int = 0
|
||||
|
||||
override fun tint() {
|
||||
applyTintColor()
|
||||
}
|
||||
|
||||
private fun applyTintColor() {
|
||||
if (backgroundTintRes != 0) {
|
||||
if (background == null) {
|
||||
background = ColorDrawable(Color.WHITE)
|
||||
}
|
||||
backgroundTintList = if (isInEditMode) {
|
||||
context.getColorStateListCompat(backgroundTintRes)
|
||||
} else {
|
||||
ColorStateListUtils.createColorStateList(context, backgroundTintRes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setBackground(background: Drawable) {
|
||||
super.setBackground(background)
|
||||
applyTintColor()
|
||||
}
|
||||
|
||||
override fun setBackgroundTintResId(resId: Int) {
|
||||
backgroundTintRes = resId
|
||||
tint()
|
||||
}
|
||||
|
||||
override fun getBackgroundTintResId(): Int {
|
||||
return backgroundTintRes
|
||||
}
|
||||
|
||||
init {
|
||||
if (attrs != null) {
|
||||
val array = getContext().obtainStyledAttributes(attrs, R.styleable.TintView, defStyleAttr, 0)
|
||||
backgroundTintRes = array.getResourceId(R.styleable.TintView_backgroundTint, 0)
|
||||
array.recycle()
|
||||
}
|
||||
applyTintColor()
|
||||
}
|
||||
}
|
||||
|
|
@ -85,14 +85,38 @@
|
|||
tools:ignore="RelativeOverlap" />
|
||||
</RelativeLayout>
|
||||
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
||||
<LinearLayout
|
||||
android:layout_marginTop="24dp"
|
||||
android:id="@+id/title_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:tint="@color/color_text_translucent_light" />
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
||||
android:id="@+id/title_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="USER"
|
||||
android:layout_gravity="center_vertical"
|
||||
app:tint="@color/color_text_translucent_light" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/user_sex"
|
||||
android:background="@drawable/bg_radius_50dp"
|
||||
android:backgroundTint="@color/user_center_action_btn_color"
|
||||
android:textColor="@color/white"
|
||||
tools:text="♂"
|
||||
android:textSize="16sp"
|
||||
android:paddingTop="1dp"
|
||||
android:paddingBottom="1dp"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
||||
android:id="@+id/user_center_slogan"
|
||||
|
|
|
|||
|
|
@ -434,4 +434,8 @@
|
|||
<string name="title_collected">已收藏</string>
|
||||
<string name="text_stat_follow">关注</string>
|
||||
<string name="text_stat_fans">粉丝</string>
|
||||
<string name="title_custom_title_style">标题样式</string>
|
||||
<string name="text_custom_title_style">Title</string>
|
||||
<string name="title_custom_font_size">字体大小</string>
|
||||
<string name="text_custom_font_size">永a</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Reference in New Issue