Commit b2f3ef49 authored by Yusuke Iwaki's avatar Yusuke Iwaki

refactor how to set color/style

parent 02b86365
......@@ -18,10 +18,9 @@
android:id="@+id/activity_main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:theme="@style/Widget.RocketChat.RoomToolbar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleText="@string/app_name"
app:titleTextColor="@color/titleTextColor"
app:titleDrawablePadding="@dimen/margin_8" />
</android.support.design.widget.AppBarLayout>
......
......@@ -19,17 +19,10 @@
android:id="@+id/activity_main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:titleText="@string/app_name"
app:titleTextColor="@color/titleTextColor"
app:titleDrawablePadding="@dimen/margin_8"
app:theme="@style/Widget.RocketChat.RoomToolbar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/button_menu"
android:background="@color/borderColor" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
......
......@@ -7,7 +7,5 @@
<color name="colorAccentDark">#FF287DD7</color>
<color name="colorAccent_a40">#662D91FA</color>
<color name="textColorLink">#008ce3</color>
<color name="titleTextColor">#444444</color>
<color name="borderColor">#eaeaea</color>
<color name="white">#FFFEFEFF</color>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.RocketChat.RoomToolbar" parent="Widget.AppCompat.Toolbar">
<item name="titleTextAppearance">@style/TextAppearance.Widget.RocketChat.RoomToolbar.Title</item>
<item name="android:background">@color/white</item>
</style>
<style name="TextAppearance.Widget.RocketChat.RoomToolbar.Title"
parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textColor">#444444</item>
</style>
</resources>
\ No newline at end of file
......@@ -2,12 +2,12 @@ package chat.rocket.android.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.View;
......@@ -41,6 +41,17 @@ public class RoomToolbar extends Toolbar {
return;
}
TypedArray typedArrayBase = context.getTheme().obtainStyledAttributes(new int[]{
R.attr.titleTextAppearance
});
try {
TextViewCompat.setTextAppearance(titleTextView,
typedArrayBase.getResourceId(0,
android.support.v7.appcompat.R.style.TextAppearance_Widget_AppCompat_Toolbar_Title));
} finally {
typedArrayBase.recycle();
}
TypedArray typedArray = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.RoomToolbar,
......@@ -48,8 +59,6 @@ public class RoomToolbar extends Toolbar {
try {
titleTextView.setText(typedArray.getText(R.styleable.RoomToolbar_titleText));
titleTextView
.setTextColor(typedArray.getColor(R.styleable.RoomToolbar_titleTextColor, Color.BLACK));
titleTextView.setCompoundDrawablePadding(
typedArray.getLayoutDimension(R.styleable.RoomToolbar_titleDrawablePadding, 0));
} finally {
......
......@@ -6,7 +6,7 @@
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" />
android:layout_height="match_parent"
android:gravity="center_vertical"/>
</merge>
\ No newline at end of file
......@@ -2,7 +2,6 @@
<resources>
<declare-styleable name="RoomToolbar">
<attr name="titleText" format="string" />
<attr name="titleTextColor" format="color" />
<attr name="titleDrawablePadding" format="dimension" />
</declare-styleable>
</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 to comment