Commit 22febcbf by 罗翻

增加自定义titlebar

parent 77d5a521
package com.dayu.bigfish.ui.views;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.dayu.bigfish.R;
/**
* Created by luofan
* on 2018/2/6.
*/
public class TitleBar extends FrameLayout {
private boolean isShowLeft;
private boolean isShowRight;
private String mTitleContent;
private String mRightContent;
private TextView mRightTitle;
private TextView mTitle;
private View mLeftTitle;
public TitleBar(@NonNull Context context) {
super(context);
initView(context, null);
}
public TitleBar(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initView(context, attrs);
}
public TitleBar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context, attrs);
}
private void initView(Context context, AttributeSet attrs) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.titleBar);
isShowLeft = typedArray.getBoolean(R.styleable.titleBar_isShowLeft, true);
isShowRight = typedArray.getBoolean(R.styleable.titleBar_isSowRight, true);
mTitleContent = typedArray.getString(R.styleable.titleBar_title);
mRightContent = typedArray.getString(R.styleable.titleBar_rightTitle);
typedArray.recycle();
View view = View.inflate(context, R.layout.title_bar_layout, this);
mRightTitle = (TextView) view.findViewById(R.id.tv_right);
mTitle = (TextView) view.findViewById(R.id.tv_title);
mLeftTitle = view.findViewById(R.id.tv_left);
mTitle.setText(mTitleContent);
mRightTitle.setText(mRightContent);
if (isShowLeft) {
mLeftTitle.setVisibility(VISIBLE);
} else {
mLeftTitle.setVisibility(GONE);
}
if (isShowRight) {
mRightTitle.setVisibility(VISIBLE);
} else {
mRightTitle.setVisibility(GONE);
}
mLeftTitle.setOnClickListener(v -> {
if (context instanceof Activity) {
((Activity) context).finish();
}
});
}
}
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/cl_home_listview_bg" android:background="@color/cl_home_listview_bg"
android:orientation="vertical"> android:orientation="vertical"
android:visibility="visible">
<RelativeLayout <RelativeLayout
android:id="@+id/title_idea" android:id="@+id/title_idea"
...@@ -38,10 +39,8 @@ ...@@ -38,10 +39,8 @@
android:onClick="@{()->presenter.dumpBack()}" /> android:onClick="@{()->presenter.dumpBack()}" />
<ImageView <ImageView
android:layout_width="match_parent" style="@style/card_line"
android:layout_height="@dimen/dp_6" android:layout_alignParentBottom="true" />
android:layout_alignParentBottom="true"
android:src="@drawable/line_shape" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/title"
android:orientation="vertical">
<TextView
android:id="@+id/tv_title"
style="@style/text_title" />
<ImageView
android:id="@+id/tv_left"
style="@style/title_image_back" />
<TextView
android:id="@+id/tv_right"
style="@style/title_right_text" />
<ImageView
style="@style/card_line"
android:layout_alignParentBottom="true" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<declare-styleable name="LRecyclerView"> <declare-styleable name="LRecyclerView">
<attr name="isReverse" format="boolean"/> <attr name="isReverse" format="boolean" />
<attr name="isRefreshable" format="boolean"/> <attr name="isRefreshable" format="boolean" />
<attr name="needCoreAdapter" format="boolean"/> <attr name="needCoreAdapter" format="boolean" />
<attr name="needFoot" format="boolean"/> <attr name="needFoot" format="boolean" />
<attr name="itemType" format="reference"/> <attr name="itemType" format="reference" />
<attr name="headType" format="reference"/> <attr name="headType" format="reference" />
<attr name="footType" format="reference"/> <attr name="footType" format="reference" />
</declare-styleable> </declare-styleable>
<attr name="backgroundCard" format="color"/> <attr name="backgroundCard" format="color" />
<attr name="textColor" format="color"/> <attr name="textColor" format="color" />
<attr name="textColorBg" format="color"/> <attr name="textColorBg" format="color" />
<attr name="themeType" format="string"/> <attr name="themeType" format="string" />
<attr name="themeIcon" format="reference"/> <attr name="themeIcon" format="reference" />
<attr name="colorWhite" format="color"/> <attr name="colorWhite" format="color" />
<declare-styleable name="titleBar">
<attr name="isShowLeft" format="boolean" />
<attr name="isSowRight" format="boolean" />
<attr name="title" format="string" />
<attr name="rightTitle" format="string" />
</declare-styleable>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment