Android 自定义状态栏
来源:互联网 发布:虎牙象棋勇哥是软件 编辑:程序博客网 时间:2024/06/04 19:03
转载自 http://blog.csdn.net/hystudio_lzu/article/details/55096774一、目标:Android5.0以上二、步骤1、在res-values-colors.xml下新建一个RGB颜色[java] view plain copy <?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color> <color name="theRed">#ff6a69</color> </resources> 2、新建一个布局,名为actionbarlayout.xml,在后边重写布局时用于添加[java] view plain copy <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/actionBarId" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> 3、重写LineaLayout布局,放置步骤二新建的布局在顶部,用作背景颜色的容器[java] view plain copy public class ActionBarLayOut extends LinearLayout { public ActionBarLayOut(Context context, AttributeSet attrs){ super(context,attrs); LayoutInflater.from(context).inflate(R.layout.actionbarlayout,this); } } 3、在主布局里调用这个重写后的线性布局[java] view plain copy <?xml version="1.0" encoding="utf-8"?> <com.example.test.ActionBarLayOut xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.test.MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/theRed" android:text="Hello World!" /> </com.example.test.ActionBarLayOut> 4、在main活动中进行相应设置[java] view plain copy public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = (TextView)findViewById(R.id.actionBarId); int color = getResources().getColor(R.color.theRed); setActionBarColor(textView,color); } protected void setActionBarColor(TextView textView, int ActionBarColor){ //----------------------------------隐藏标题栏---------------------------------------------- if (getSupportActionBar()!=null) { getSupportActionBar().hide(); } //------------------------------------------------------------------------------------------ //----------------------------------将状态栏设置为透明-------------------------------------- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.TRANSPARENT); window.setNavigationBarColor(Color.TRANSPARENT); } //------------------------------------------------------------------------------------------ /** * 首先获取状态栏的高度statusBarHeight1,然后在状态栏的位置放一个空的TextView, * 高度设置为statusBarHeight1,然后将TextView的背景颜色进行设置,这样就可以变相 * 的给状态栏设置颜色 */ int statusBarHeight1 = -1; //获取status_bar_height资源的ID int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { //根据资源ID获取响应的尺寸值 statusBarHeight1 = getResources().getDimensionPixelSize(resourceId); } textView.setHeight(statusBarHeight1); textView.setBackgroundColor(ActionBarColor); } }
0 0
- Android实现自定义状态栏
- android自定义状态栏!!1
- android自定义状态栏颜色
- 【Android】自定义状态栏通知
- Android自定义下载状态栏
- Android自定义状态栏颜色
- android 自定义状态栏颜色
- Android自定义状态栏颜色
- Android 自定义状态栏
- Android开发自定义状态栏
- Android自定义状态栏颜色
- Android自定义状态栏颜色、状态栏透明
- Android 状态栏透明、自定义状态栏颜色设置
- android 自定义顶部状态栏颜色
- android自定义状态栏的颜色
- Android自定义通知栏/状态栏颜色
- android 状态栏透明 自定义AppTheme 轻松实现
- Android中自定义顶部状态栏颜色
- 并查集详解
- 11. JDK 新特性
- 利用redis同步登陆实现session共享
- PAT 1093 CountPAT
- 404. Sum of Left Leaves | 所有左子树的和
- Android 自定义状态栏
- 杨辉三角
- 前端技能练习:javascript基础:修改this指针
- 13. 总结 JavaSE
- 树状数组(二)与poj2155
- WIN10下使用qt mingw64_4.9.2编译box2d
- 标识符
- Java HashTable HashMap ConcurrentHashMap 对比选择
- [mmc subsystem] mmc core(第二章)——数据结构和宏定义说明