Skip to content

Commit

Permalink
优化修改状态栏的颜色
Browse files Browse the repository at this point in the history
  • Loading branch information
lee committed Nov 6, 2019
1 parent 6261ecf commit d10733f
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Main2Activity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/example/myapplication/Main2Activity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class Main2Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
}
25 changes: 14 additions & 11 deletions app/src/main/java/com/example/myapplication/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.myapplication;

import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.widget.Button;

Expand Down Expand Up @@ -32,6 +33,7 @@ protected int onRegistered() {
@Override
protected void initView() {
EventBusUtils.register(this);
Log.i("testId", bindId(R.id.ctl_content).getId() + "");

}

Expand All @@ -52,17 +54,18 @@ protected void initListener() {
public void onClick(View view) {
switch (view.getId()) {
case R.id.tv_test:
new BottomIosDialog(this) {
@Override
protected List<String> getItems() {
return new ListUtils<String>().add("播放完当前声音结束", "5分钟", "15分钟", "30分钟", "60分钟");
}

@Override
protected void itemClicks(Button button, int position) {

}
}.setBackgroundColor(Color.parseColor("#000000")).setLineColor(Color.parseColor("#565656")).setCancelShow(false).show();
jumpActivity(Main2Activity.class);
// new BottomIosDialog(this) {
// @Override
// protected List<String> getItems() {
// return new ListUtils<String>().add("播放完当前声音结束", "5分钟", "15分钟", "30分钟", "60分钟");
// }
//
// @Override
// protected void itemClicks(Button button, int position) {
//
// }
// }.setBackgroundColor(Color.parseColor("#000000")).setLineColor(Color.parseColor("#565656")).setCancelShow(false).show();
break;
}
}
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:context=".MainActivity"
android:id="@+id/ctl_content"
>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ctl_title"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/colorAccent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="我是title" />

</androidx.constraintlayout.widget.ConstraintLayout>


<TextView
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/activity_main2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main2Activity">

</androidx.constraintlayout.widget.ConstraintLayout>
5 changes: 1 addition & 4 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroupOverlay;
import android.view.Window;
import android.view.WindowManager;
import android.widget.DatePicker;
import android.widget.FrameLayout;
Expand All @@ -26,8 +28,12 @@

import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.fragment.app.Fragment;

import com.example.mypubliclibrary.R;
import com.example.mypubliclibrary.base.BasesActivity;
import com.example.mypubliclibrary.base.BasesFragment;
import com.example.mypubliclibrary.widget.dialog.WarningDialog;
import com.example.mypubliclibrary.widget.interfaces.DataInterface;
import com.example.mypubliclibrary.widget.interfaces.DateInterface;
Expand Down Expand Up @@ -93,14 +99,26 @@ public static void setStatusTitle(Context context, View titleView, boolean isSet
if (titleView != null) {
int statusHeight = getStatusBarHeight(context);
ViewGroup.LayoutParams layoutParams = titleView.getLayoutParams();
ConstraintLayout layout = (ConstraintLayout) ((ViewGroup) titleView.getRootView().findViewById(android.R.id.content)).getChildAt(0);
View view = layout.findViewById(R.id.status_back);
if (view == null) {
view = new View(context);
//添加状态栏View
ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, 0);
params.topToTop = ConstraintSet.PARENT_ID;
params.bottomToTop = titleView.getId();
layout.addView(view, params);
}
//设置间距
setLayoutMargin(layoutParams, 0, statusHeight, 0, 0);
if (isSetStatusColor) {
//设置状态栏的背景色
ColorDrawable colorDrawable = (ColorDrawable) titleView.getBackground();
if (colorDrawable != null) {
//设置状态栏背景色为标题背景色
((Activity) context).getWindow().setStatusBarColor(colorDrawable.getColor());
view.setBackgroundColor(colorDrawable.getColor());
//设置状态栏背景色为标题背景色
// ((Activity) context).getWindow().setStatusBarColor(colorDrawable.getColor());
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<translate
android:duration="220"
android:fromYDelta="100%"
android:fromYDelta="100%p"
android:toYDelta="0" />

</set>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<translate
android:duration="720"
android:fromYDelta="0"
android:toYDelta="100%" />
android:toYDelta="100%p" />

</set>
4 changes: 4 additions & 0 deletions mypubliclibrary/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="status_back" />
</resources>

0 comments on commit d10733f

Please sign in to comment.