Skip to content

Commit 9d1d053

Browse files
committed
修改高亮显示
1 parent 0df8bbb commit 9d1d053

File tree

5 files changed

+68
-54
lines changed

5 files changed

+68
-54
lines changed

app/src/main/kotlin/com/rayfantasy/icode/model/ICodeTheme.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ object ICodeTheme {
3838
R.color.colorPrimaryDark_purple, R.color.colorPrimaryDark_gray, R.color.colorPrimaryDark_yellow, R.color.colorPrimaryDark_deepblue)
3939
internal val colorAccentRes = intArrayOf(R.color.colorAccent_blue, R.color.colorAccent_red,
4040
R.color.colorAccent_purple, R.color.colorAccent_gray, R.color.colorAccent_yellow, R.color.colorAccent_deepblue)
41+
internal val colorHighLightRes = intArrayOf(R.color.high_light_blue, R.color.high_light_red,
42+
R.color.high_light_purple, R.color.high_light_gray, R.color.high_light_yellow, R.color.high_light_deepblue)
4143

4244
fun init(ctx: Context) {
4345
val theme = ctx.defaultSharedPreferences.getInt(PREF_ICODE_THEME, THEME_DEFAULT)
@@ -50,13 +52,16 @@ object ICodeTheme {
5052

5153
val colorAccent = ObservableInt()
5254

55+
val colorHighLight = ObservableInt()
56+
5357
val icon = ObservableInt()
5458
}
5559

5660
fun Context.changeTheme(theme: Int) = with(ICodeTheme) {
5761
changeColor(colorPrimary, resources.getColor(colorPrimaryRes[theme]))
5862
changeColor(colorPrimaryDark, resources.getColor(colorPrimaryDarkRes[theme]))
5963
changeColor(colorAccent, resources.getColor(colorAccentRes[theme]))
64+
changeColor(colorHighLight, resources.getColor(colorHighLightRes[theme]))
6065
defaultSharedPreferences.edit().putInt(PREF_ICODE_THEME, theme).apply()
6166
}
6267

@@ -68,7 +73,7 @@ fun changeColor(observableInt: ObservableInt, color: Int) {
6873
anim.addUpdateListener {
6974
observableInt.set(it.animatedValue as Int)
7075
}
71-
anim.setDuration(300)
76+
anim.duration = 300
7277
anim.start()
7378
} else
7479
observableInt.set(color)

app/src/main/kotlin/com/rayfantasy/icode/ui/activity/MainActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ class MainActivity : ActivityBase(), NavigationView.OnNavigationItemSelectedList
8080
drawer_layout.setDrawerListener(toggle)
8181
toggle.syncState()
8282
nav_view.setNavigationItemSelectedListener(this)
83-
configuration(fromSdk = Build.VERSION_CODES.LOLLIPOP) { drawer_layout.fitsSystemWindows = true }
83+
configuration(sdk = Build.VERSION_CODES.KITKAT) {
84+
drawer_layout.fitsSystemWindows = false
85+
}
8486

8587
val headerView = nav_view.getHeaderView(0)
8688
NvLayoutBinding.bind(headerView).theme = ICodeTheme

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
android:id="@+id/drawer_layout"
1616
android:layout_width="match_parent"
1717
android:layout_height="match_parent"
18+
android:fitsSystemWindows="true"
1819
app:statusBarBackgroundColor="@{theme.colorPrimaryDark}"
1920
tools:openDrawer="start">
2021

app/src/main/res/layout/item_code_list.xml

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
</data>
1515

1616
<android.support.v7.widget.CardView
17-
android:layout_width="match_parent"
1817
android:id="@+id/code_card"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
1920
android:layout_marginBottom="2dp"
2021
android:layout_marginTop="2dp"
2122
android:foreground="?android:attr/selectableItemBackground"
22-
android:layout_height="wrap_content">
23+
app:cardBackgroundColor="@{highlight ? theme.colorHighLight : 0}">
2324

2425
<LinearLayout
2526
android:layout_width="match_parent"
26-
android:orientation="vertical"
2727
android:layout_height="wrap_content"
28+
android:orientation="vertical"
2829
android:weightSum="1">
2930

3031
<RelativeLayout
@@ -33,120 +34,124 @@
3334
android:layout_marginBottom="4dp">
3435

3536
<ImageView
37+
android:id="@+id/code_usericon"
3638
android:layout_width="@dimen/profile_pic_size"
3739
android:layout_height="@dimen/profile_pic_size"
38-
android:id="@+id/code_usericon"
39-
android:src="@mipmap/ic_account_box_black"
4040
android:layout_marginLeft="16dp"
41-
android:layout_marginTop="5dp" />
41+
android:layout_marginTop="5dp"
42+
android:src="@mipmap/ic_account_box_black" />
4243

4344
<TextView
45+
android:id="@+id/code_username"
4446
android:layout_width="wrap_content"
4547
android:layout_height="wrap_content"
46-
android:id="@+id/code_username"
47-
android:text="Username"
48-
android:textColor="@{highlight ? theme.colorAccent : 0xFF8C8C8C}"
4948
android:layout_centerVertical="true"
50-
android:layout_toRightOf="@+id/code_usericon"
49+
android:layout_marginLeft="15dp"
5150
android:layout_toEndOf="@+id/code_usericon"
52-
android:layout_marginLeft="15dp" />
51+
android:layout_toRightOf="@+id/code_usericon"
52+
android:text="Username"
53+
android:textColor="@{highlight ? (int) @android:color/white : (int) @color/secondary_text_default_material_light}" />
5354

5455
<TextView
56+
android:id="@+id/code_time"
5557
android:layout_width="wrap_content"
5658
android:layout_height="wrap_content"
57-
android:id="@+id/code_time"
58-
android:text="time"
59-
android:textColor="@{highlight ? theme.colorAccent : 0xFF8C8C8C}"
60-
android:layout_marginRight="16dp"
61-
android:layout_centerVertical="true"
62-
android:layout_alignParentRight="true"
6359
android:layout_alignParentEnd="true"
64-
android:layout_marginEnd="16dp" />
60+
android:layout_alignParentRight="true"
61+
android:layout_centerVertical="true"
62+
android:layout_marginEnd="16dp"
63+
android:layout_marginRight="16dp"
64+
android:text="time"
65+
android:textColor="@{highlight ? (int) @android:color/white : (int) @color/secondary_text_default_material_light}" />
6566

6667
</RelativeLayout>
6768

6869
<LinearLayout
6970
android:layout_width="match_parent"
70-
android:background="#dddd"
7171
android:layout_height="1dp"
7272
android:layout_marginLeft="10dp"
73-
android:layout_marginRight="10dp">
73+
android:layout_marginRight="10dp"
74+
android:background="#dddd">
7475

7576
</LinearLayout>
7677

7778
<LinearLayout
7879
android:layout_width="match_parent"
7980
android:layout_height="match_parent"
80-
android:orientation="vertical"
81-
android:layout_marginBottom="3dp">
81+
android:layout_marginBottom="3dp"
82+
android:orientation="vertical">
8283

8384
<TextView
85+
android:id="@+id/code_title"
8486
android:layout_width="wrap_content"
8587
android:layout_height="wrap_content"
86-
android:id="@+id/code_title"
87-
android:textColor="@{highlight ? theme.colorAccent : theme.colorPrimaryDark}"
88-
android:text="Title"
8988
android:layout_marginLeft="16dp"
89+
android:text="Title"
90+
android:textColor="@{highlight ? (int) @android:color/white : theme.colorPrimaryDark}"
9091
android:textSize="20dp" />
9192

9293
<TextView
94+
android:id="@+id/code_subtitle"
9395
android:layout_width="wrap_content"
9496
android:layout_height="wrap_content"
95-
android:text="subtitle"
96-
android:id="@+id/code_subtitle"
97-
android:layout_marginLeft="16dp"
98-
android:textColor="@{highlight ? theme.colorAccent : 0xFF8C8C8C}"
9997
android:layout_alignParentTop="true"
100-
android:layout_toRightOf="@+id/code_title"
98+
android:layout_marginLeft="16dp"
99+
android:layout_marginTop="3dp"
101100
android:layout_toEndOf="@+id/code_title"
102-
android:layout_marginTop="3dp" />
101+
android:layout_toRightOf="@+id/code_title"
102+
android:text="subtitle"
103+
android:textColor="@{highlight ? (int) @android:color/white : (int) @color/secondary_text_default_material_light}" />
103104
</LinearLayout>
105+
104106
<LinearLayout
105107
android:layout_width="match_parent"
106-
android:background="#dddd"
107108
android:layout_height="1dp"
109+
android:layout_marginLeft="10dp"
108110
android:layout_marginRight="10dp"
109-
android:layout_marginLeft="10dp">
111+
android:background="#dddd">
110112

111113
</LinearLayout>
114+
112115
<RelativeLayout
113116
android:layout_width="match_parent"
114117
android:layout_height="wrap_content">
115118

116119

117120
<com.like.LikeButton
118-
app:icon_type="heart"
119-
app:icon_size="16dp"
120121
android:id="@+id/code_like"
121122
android:layout_width="wrap_content"
122123
android:layout_height="wrap_content"
123-
android:layout_alignParentTop="true"
124124
android:layout_alignParentLeft="true"
125125
android:layout_alignParentStart="true"
126+
android:layout_alignParentTop="true"
126127
android:layout_marginLeft="16dp"
127-
android:layout_marginStart="15dp" />
128+
android:layout_marginStart="15dp"
129+
app:icon_size="16dp"
130+
app:icon_type="heart" />
128131

129132
<TextView
133+
android:id="@+id/code_favoCount"
130134
android:layout_width="wrap_content"
131135
android:layout_height="wrap_content"
132-
android:text="Favo_Count"
133-
android:id="@+id/code_favoCount"
134136
android:layout_centerVertical="true"
135-
android:layout_toRightOf="@+id/code_like"
137+
android:layout_marginLeft="5dp"
136138
android:layout_toEndOf="@+id/code_like"
137-
android:layout_marginLeft="5dp" />
139+
android:layout_toRightOf="@+id/code_like"
140+
android:text="Favo_Count"
141+
android:textColor="@{highlight ? (int) @android:color/white : (int) @color/secondary_text_default_material_light}" />
138142

139143
<TextView
144+
android:id="@+id/code_replyCount"
140145
android:layout_width="wrap_content"
141146
android:layout_height="wrap_content"
142-
android:text="reply_Count"
143-
android:id="@+id/code_replyCount"
144-
android:layout_alignTop="@+id/code_favoCount"
145-
android:layout_alignParentRight="true"
146147
android:layout_alignParentEnd="true"
147-
android:layout_marginRight="16dp"
148+
android:layout_alignParentRight="true"
149+
android:layout_alignTop="@+id/code_favoCount"
148150
android:layout_marginEnd="16dp"
149-
android:layout_marginTop="14dp" />
151+
android:layout_marginRight="16dp"
152+
android:layout_marginTop="14dp"
153+
android:textColor="@{highlight ? (int) @android:color/white : (int) @color/secondary_text_default_material_light}" />
154+
android:text="reply_Count" />
150155
</RelativeLayout>
151156
</LinearLayout>
152157
</android.support.v7.widget.CardView>

app/src/main/res/values/colors.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@
5050
<color name="colorAccent_deepblue">#ff4081</color>
5151

5252
<!--code高亮颜色-->
53-
<color name="hight_light_brown">#724938</color>
54-
<color name="hight_light_blue">#0D5661</color>
55-
<color name="hight_light_purple">#3C2F41</color>
56-
<color name="hight_light_red">#CB4042</color>
57-
<color name="hight_light_yellow">#F05E1C</color>
53+
<color name="high_light_blue">#0D5661</color>
54+
<color name="high_light_purple">#3C2F41</color>
55+
<color name="high_light_red">#CB4042</color>
56+
<color name="high_light_yellow">#F05E1C</color>
57+
<color name="high_light_deepblue">#2E5C6E</color>
58+
<color name="high_light_gray">#373C38</color>
5859

5960

6061
</resources>

0 commit comments

Comments
 (0)