必须在Android4.4以上版本才能设置状态栏颜色;

一、在单个Activity里面,设置状态栏的背景:

  效果: 

  1、在Activity的布局根文件中添加属性:

  1.       android:fitsSystemWindows="true"   //不设置此属性,标题栏和系统状态栏会重叠

  2、将第三方核心代码类 SystemBarTintManager 复制到自己的项目:

  1. /*
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15.  
  16. package com.xczl.smart.application;
  17.  
  18. import android.annotation.SuppressLint;
  19. import android.annotation.TargetApi;
  20. import android.app.Activity;
  21. import android.content.Context;
  22. import android.content.res.Configuration;
  23. import android.content.res.Resources;
  24. import android.content.res.TypedArray;
  25. import android.graphics.drawable.Drawable;
  26. import android.os.Build;
  27. import android.util.DisplayMetrics;
  28. import android.util.TypedValue;
  29. import android.view.Gravity;
  30. import android.view.View;
  31. import android.view.ViewConfiguration;
  32. import android.view.ViewGroup;
  33. import android.view.Window;
  34. import android.view.WindowManager;
  35. import android.widget.FrameLayout.LayoutParams;
  36.  
  37. import java.lang.reflect.Method;
  38.  
  39. /**
  40. * Class to manage status and navigation bar tint effects when using KitKat
  41. * translucent system UI modes.
  42. *
  43. */
  44. public class SystemBarTintManager {
  45.  
  46. static {
  47. // Android allows a system property to override the presence of the navigation bar.
  48. // Used by the emulator.
  49. // See https://github.com/android/platform_frameworks_base/blob/master/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java#L1076
  50. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  51. try {
  52. Class c = Class.forName("android.os.SystemProperties");
  53. Method m = c.getDeclaredMethod("get", String.class);
  54. m.setAccessible(true);
  55. sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");
  56. } catch (Throwable e) {
  57. sNavBarOverride = null;
  58. }
  59. }
  60. }
  61.  
  62. /**
  63. * The default system bar tint color value.
  64. */
  65. public static final int DEFAULT_TINT_COLOR = 0x99000000;
  66.  
  67. private static String sNavBarOverride;
  68.  
  69. private final SystemBarConfig mConfig;
  70. private boolean mStatusBarAvailable;
  71. private boolean mNavBarAvailable;
  72. private boolean mStatusBarTintEnabled;
  73. private boolean mNavBarTintEnabled;
  74. private View mStatusBarTintView;
  75. private View mNavBarTintView;
  76.  
  77. /**
  78. * Constructor. Call this in the host activity onCreate method after its
  79. * content view has been set. You should always create new instances when
  80. * the host activity is recreated.
  81. *
  82. * @param activity The host activity.
  83. */
  84. @TargetApi(19)
  85. public SystemBarTintManager(Activity activity) {
  86.  
  87. Window win = activity.getWindow();
  88. ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();
  89.  
  90. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  91. // check theme attrs
  92. int[] attrs = {android.R.attr.windowTranslucentStatus,
  93. android.R.attr.windowTranslucentNavigation};
  94. TypedArray a = activity.obtainStyledAttributes(attrs);
  95. try {
  96. mStatusBarAvailable = a.getBoolean(0, false);
  97. mNavBarAvailable = a.getBoolean(1, false);
  98. } finally {
  99. a.recycle();
  100. }
  101.  
  102. // check window flags
  103. WindowManager.LayoutParams winParams = win.getAttributes();
  104. int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
  105. if ((winParams.flags & bits) != 0) {
  106. mStatusBarAvailable = true;
  107. }
  108. bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
  109. if ((winParams.flags & bits) != 0) {
  110. mNavBarAvailable = true;
  111. }
  112. }
  113.  
  114. mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable);
  115. // device might not have virtual navigation keys
  116. if (!mConfig.hasNavigtionBar()) {
  117. mNavBarAvailable = false;
  118. }
  119.  
  120. if (mStatusBarAvailable) {
  121. setupStatusBarView(activity, decorViewGroup);
  122. }
  123. if (mNavBarAvailable) {
  124. setupNavBarView(activity, decorViewGroup);
  125. }
  126.  
  127. }
  128.  
  129. /**
  130. * Enable tinting of the system status bar.
  131. *
  132. * If the platform is running Jelly Bean or earlier, or translucent system
  133. * UI modes have not been enabled in either the theme or via window flags,
  134. * then this method does nothing.
  135. *
  136. * @param enabled True to enable tinting, false to disable it (default).
  137. */
  138. public void setStatusBarTintEnabled(boolean enabled) {
  139. mStatusBarTintEnabled = enabled;
  140. if (mStatusBarAvailable) {
  141. mStatusBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE);
  142. }
  143. }
  144.  
  145. /**
  146. * Enable tinting of the system navigation bar.
  147. *
  148. * If the platform does not have soft navigation keys, is running Jelly Bean
  149. * or earlier, or translucent system UI modes have not been enabled in either
  150. * the theme or via window flags, then this method does nothing.
  151. *
  152. * @param enabled True to enable tinting, false to disable it (default).
  153. */
  154. public void setNavigationBarTintEnabled(boolean enabled) {
  155. mNavBarTintEnabled = enabled;
  156. if (mNavBarAvailable) {
  157. mNavBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE);
  158. }
  159. }
  160.  
  161. /**
  162. * Apply the specified color tint to all system UI bars.
  163. *
  164. * @param color The color of the background tint.
  165. */
  166. public void setTintColor(int color) {
  167. setStatusBarTintColor(color);
  168. setNavigationBarTintColor(color);
  169. }
  170.  
  171. /**
  172. * Apply the specified drawable or color resource to all system UI bars.
  173. *
  174. * @param res The identifier of the resource.
  175. */
  176. public void setTintResource(int res) {
  177. setStatusBarTintResource(res);
  178. setNavigationBarTintResource(res);
  179. }
  180.  
  181. /**
  182. * Apply the specified drawable to all system UI bars.
  183. *
  184. * @param drawable The drawable to use as the background, or null to remove it.
  185. */
  186. public void setTintDrawable(Drawable drawable) {
  187. setStatusBarTintDrawable(drawable);
  188. setNavigationBarTintDrawable(drawable);
  189. }
  190.  
  191. /**
  192. * Apply the specified alpha to all system UI bars.
  193. *
  194. * @param alpha The alpha to use
  195. */
  196. public void setTintAlpha(float alpha) {
  197. setStatusBarAlpha(alpha);
  198. setNavigationBarAlpha(alpha);
  199. }
  200.  
  201. /**
  202. * Apply the specified color tint to the system status bar.
  203. *
  204. * @param color The color of the background tint.
  205. */
  206. public void setStatusBarTintColor(int color) {
  207. if (mStatusBarAvailable) {
  208. mStatusBarTintView.setBackgroundColor(color);
  209. }
  210. }
  211.  
  212. /**
  213. * Apply the specified drawable or color resource to the system status bar.
  214. *
  215. * @param res The identifier of the resource.
  216. */
  217. public void setStatusBarTintResource(int res) {
  218. if (mStatusBarAvailable) {
  219. mStatusBarTintView.setBackgroundResource(res);
  220. }
  221. }
  222.  
  223. /**
  224. * Apply the specified drawable to the system status bar.
  225. *
  226. * @param drawable The drawable to use as the background, or null to remove it.
  227. */
  228. @SuppressWarnings("deprecation")
  229. public void setStatusBarTintDrawable(Drawable drawable) {
  230. if (mStatusBarAvailable) {
  231. mStatusBarTintView.setBackgroundDrawable(drawable);
  232. }
  233. }
  234.  
  235. /**
  236. * Apply the specified alpha to the system status bar.
  237. *
  238. * @param alpha The alpha to use
  239. */
  240. @TargetApi(11)
  241. public void setStatusBarAlpha(float alpha) {
  242. if (mStatusBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
  243. mStatusBarTintView.setAlpha(alpha);
  244. }
  245. }
  246.  
  247. /**
  248. * Apply the specified color tint to the system navigation bar.
  249. *
  250. * @param color The color of the background tint.
  251. */
  252. public void setNavigationBarTintColor(int color) {
  253. if (mNavBarAvailable) {
  254. mNavBarTintView.setBackgroundColor(color);
  255. }
  256. }
  257.  
  258. /**
  259. * Apply the specified drawable or color resource to the system navigation bar.
  260. *
  261. * @param res The identifier of the resource.
  262. */
  263. public void setNavigationBarTintResource(int res) {
  264. if (mNavBarAvailable) {
  265. mNavBarTintView.setBackgroundResource(res);
  266. }
  267. }
  268.  
  269. /**
  270. * Apply the specified drawable to the system navigation bar.
  271. *
  272. * @param drawable The drawable to use as the background, or null to remove it.
  273. */
  274. @SuppressWarnings("deprecation")
  275. public void setNavigationBarTintDrawable(Drawable drawable) {
  276. if (mNavBarAvailable) {
  277. mNavBarTintView.setBackgroundDrawable(drawable);
  278. }
  279. }
  280.  
  281. /**
  282. * Apply the specified alpha to the system navigation bar.
  283. *
  284. * @param alpha The alpha to use
  285. */
  286. @TargetApi(11)
  287. public void setNavigationBarAlpha(float alpha) {
  288. if (mNavBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
  289. mNavBarTintView.setAlpha(alpha);
  290. }
  291. }
  292.  
  293. /**
  294. * Get the system bar configuration.
  295. *
  296. * @return The system bar configuration for the current device configuration.
  297. */
  298. public SystemBarConfig getConfig() {
  299. return mConfig;
  300. }
  301.  
  302. /**
  303. * Is tinting enabled for the system status bar?
  304. *
  305. * @return True if enabled, False otherwise.
  306. */
  307. public boolean isStatusBarTintEnabled() {
  308. return mStatusBarTintEnabled;
  309. }
  310.  
  311. /**
  312. * Is tinting enabled for the system navigation bar?
  313. *
  314. * @return True if enabled, False otherwise.
  315. */
  316. public boolean isNavBarTintEnabled() {
  317. return mNavBarTintEnabled;
  318. }
  319.  
  320. private void setupStatusBarView(Context context, ViewGroup decorViewGroup) {
  321. mStatusBarTintView = new View(context);
  322. LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight());
  323. params.gravity = Gravity.TOP;
  324. if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) {
  325. params.rightMargin = mConfig.getNavigationBarWidth();
  326. }
  327. mStatusBarTintView.setLayoutParams(params);
  328. mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
  329. mStatusBarTintView.setVisibility(View.GONE);
  330. decorViewGroup.addView(mStatusBarTintView);
  331. }
  332.  
  333. private void setupNavBarView(Context context, ViewGroup decorViewGroup) {
  334. mNavBarTintView = new View(context);
  335. LayoutParams params;
  336. if (mConfig.isNavigationAtBottom()) {
  337. params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getNavigationBarHeight());
  338. params.gravity = Gravity.BOTTOM;
  339. } else {
  340. params = new LayoutParams(mConfig.getNavigationBarWidth(), LayoutParams.MATCH_PARENT);
  341. params.gravity = Gravity.RIGHT;
  342. }
  343. mNavBarTintView.setLayoutParams(params);
  344. mNavBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
  345. mNavBarTintView.setVisibility(View.GONE);
  346. decorViewGroup.addView(mNavBarTintView);
  347. }
  348.  
  349. /**
  350. * Class which describes system bar sizing and other characteristics for the current
  351. * device configuration.
  352. *
  353. */
  354. public static class SystemBarConfig {
  355.  
  356. private static final String STATUS_BAR_HEIGHT_RES_NAME = "status_bar_height";
  357. private static final String NAV_BAR_HEIGHT_RES_NAME = "navigation_bar_height";
  358. private static final String NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME = "navigation_bar_height_landscape";
  359. private static final String NAV_BAR_WIDTH_RES_NAME = "navigation_bar_width";
  360. private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar";
  361.  
  362. private final boolean mTranslucentStatusBar;
  363. private final boolean mTranslucentNavBar;
  364. private final int mStatusBarHeight;
  365. private final int mActionBarHeight;
  366. private final boolean mHasNavigationBar;
  367. private final int mNavigationBarHeight;
  368. private final int mNavigationBarWidth;
  369. private final boolean mInPortrait;
  370. private final float mSmallestWidthDp;
  371.  
  372. private SystemBarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) {
  373. Resources res = activity.getResources();
  374. mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
  375. mSmallestWidthDp = getSmallestWidthDp(activity);
  376. mStatusBarHeight = getInternalDimensionSize(res, STATUS_BAR_HEIGHT_RES_NAME);
  377. mActionBarHeight = getActionBarHeight(activity);
  378. mNavigationBarHeight = getNavigationBarHeight(activity);
  379. mNavigationBarWidth = getNavigationBarWidth(activity);
  380. mHasNavigationBar = (mNavigationBarHeight > 0);
  381. mTranslucentStatusBar = translucentStatusBar;
  382. mTranslucentNavBar = traslucentNavBar;
  383. }
  384.  
  385. @TargetApi(14)
  386. private int getActionBarHeight(Context context) {
  387. int result = 0;
  388. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
  389. TypedValue tv = new TypedValue();
  390. context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
  391. result = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
  392. }
  393. return result;
  394. }
  395.  
  396. @TargetApi(14)
  397. private int getNavigationBarHeight(Context context) {
  398. Resources res = context.getResources();
  399. int result = 0;
  400. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
  401. if (hasNavBar(context)) {
  402. String key;
  403. if (mInPortrait) {
  404. key = NAV_BAR_HEIGHT_RES_NAME;
  405. } else {
  406. key = NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME;
  407. }
  408. return getInternalDimensionSize(res, key);
  409. }
  410. }
  411. return result;
  412. }
  413.  
  414. @TargetApi(14)
  415. private int getNavigationBarWidth(Context context) {
  416. Resources res = context.getResources();
  417. int result = 0;
  418. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
  419. if (hasNavBar(context)) {
  420. return getInternalDimensionSize(res, NAV_BAR_WIDTH_RES_NAME);
  421. }
  422. }
  423. return result;
  424. }
  425.  
  426. @TargetApi(14)
  427. private boolean hasNavBar(Context context) {
  428. Resources res = context.getResources();
  429. int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android");
  430. if (resourceId != 0) {
  431. boolean hasNav = res.getBoolean(resourceId);
  432. // check override flag (see static block)
  433. if ("1".equals(sNavBarOverride)) {
  434. hasNav = false;
  435. } else if ("0".equals(sNavBarOverride)) {
  436. hasNav = true;
  437. }
  438. return hasNav;
  439. } else { // fallback
  440. return !ViewConfiguration.get(context).hasPermanentMenuKey();
  441. }
  442. }
  443.  
  444. private int getInternalDimensionSize(Resources res, String key) {
  445. int result = 0;
  446. int resourceId = res.getIdentifier(key, "dimen", "android");
  447. if (resourceId > 0) {
  448. result = res.getDimensionPixelSize(resourceId);
  449. }
  450. return result;
  451. }
  452.  
  453. @SuppressLint("NewApi")
  454. private float getSmallestWidthDp(Activity activity) {
  455. DisplayMetrics metrics = new DisplayMetrics();
  456. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
  457. activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
  458. } else {
  459. // TODO this is not correct, but we don't really care pre-kitkat
  460. activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
  461. }
  462. float widthDp = metrics.widthPixels / metrics.density;
  463. float heightDp = metrics.heightPixels / metrics.density;
  464. return Math.min(widthDp, heightDp);
  465. }
  466.  
  467. /**
  468. * Should a navigation bar appear at the bottom of the screen in the current
  469. * device configuration? A navigation bar may appear on the right side of
  470. * the screen in certain configurations.
  471. *
  472. * @return True if navigation should appear at the bottom of the screen, False otherwise.
  473. */
  474. public boolean isNavigationAtBottom() {
  475. return (mSmallestWidthDp >= 600 || mInPortrait);
  476. }
  477.  
  478. /**
  479. * Get the height of the system status bar.
  480. *
  481. * @return The height of the status bar (in pixels).
  482. */
  483. public int getStatusBarHeight() {
  484. return mStatusBarHeight;
  485. }
  486.  
  487. /**
  488. * Get the height of the action bar.
  489. *
  490. * @return The height of the action bar (in pixels).
  491. */
  492. public int getActionBarHeight() {
  493. return mActionBarHeight;
  494. }
  495.  
  496. /**
  497. * Does this device have a system navigation bar?
  498. *
  499. * @return True if this device uses soft key navigation, False otherwise.
  500. */
  501. public boolean hasNavigtionBar() {
  502. return mHasNavigationBar;
  503. }
  504.  
  505. /**
  506. * Get the height of the system navigation bar.
  507. *
  508. * @return The height of the navigation bar (in pixels). If the device does not have
  509. * soft navigation keys, this will always return 0.
  510. */
  511. public int getNavigationBarHeight() {
  512. return mNavigationBarHeight;
  513. }
  514.  
  515. /**
  516. * Get the width of the system navigation bar when it is placed vertically on the screen.
  517. *
  518. * @return The width of the navigation bar (in pixels). If the device does not have
  519. * soft navigation keys, this will always return 0.
  520. */
  521. public int getNavigationBarWidth() {
  522. return mNavigationBarWidth;
  523. }
  524.  
  525. /**
  526. * Get the layout inset for any system UI that appears at the top of the screen.
  527. *
  528. * @param withActionBar True to include the height of the action bar, False otherwise.
  529. * @return The layout inset (in pixels).
  530. */
  531. public int getPixelInsetTop(boolean withActionBar) {
  532. return (mTranslucentStatusBar ? mStatusBarHeight : 0) + (withActionBar ? mActionBarHeight : 0);
  533. }
  534.  
  535. /**
  536. * Get the layout inset for any system UI that appears at the bottom of the screen.
  537. *
  538. * @return The layout inset (in pixels).
  539. */
  540. public int getPixelInsetBottom() {
  541. if (mTranslucentNavBar && isNavigationAtBottom()) {
  542. return mNavigationBarHeight;
  543. } else {
  544. return 0;
  545. }
  546. }
  547.  
  548. /**
  549. * Get the layout inset for any system UI that appears at the right of the screen.
  550. *
  551. * @return The layout inset (in pixels).
  552. */
  553. public int getPixelInsetRight() {
  554. if (mTranslucentNavBar && !isNavigationAtBottom()) {
  555. return mNavigationBarWidth;
  556. } else {
  557. return 0;
  558. }
  559. }
  560.  
  561. }
  562.  
  563. }

  3、在Activity代码中进行设置:

  

  1.   
  2.     @Override
  3.     protected void onCreate(Bundle savedInstanceState) {
  4.           super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_login);
  5.  
  6. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //系统版本大于19
  7. setTranslucentStatus(true);
  8. }
  9. SystemBarTintManager tintManager = new SystemBarTintManager(this);
  10. tintManager.setStatusBarTintEnabled(true);
  11. tintManager.setStatusBarTintResource(R.color.title_green);      //设置标题栏颜色,此颜色在color中声明
  12. }
  13. @TargetApi(19)
  14. private void setTranslucentStatus(boolean on) {
  15. Window win = getWindow();
  16. WindowManager.LayoutParams winParams = win.getAttributes();
  17. final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
  18. if (on) {
  19. winParams.flags |= bits; // a|=b的意思就是把a和b按位或然后赋值给a 按位或的意思就是先把a和b都换成2进制,然后用或操作,相当于a=a|b
  20. } else {
  21. winParams.flags &= ~bits; //&是位运算里面,与运算 a&=b相当于 a = a&b ~非运算符
  22. }
  23. win.setAttributes(winParams);
  24. }

二、设置状态栏字体为黑色,判断版本,并添加代码:

  效果:  

  1. setContentView(R.layout.activity_login);
  2. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //系统版本大于19
  3. setTranslucentStatus(true);
  4. }
  5. SystemBarTintManager tintManager = new SystemBarTintManager(this);
  6. tintManager.setStatusBarTintEnabled(true);
  7. tintManager.setStatusBarTintResource(R.color.title_green);
  8. Class clazz = this.getWindow().getClass();
  9. try {
  10. int darkModeFlag = 0;
  11. Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
  12. Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
  13. darkModeFlag = field.getInt(layoutParams);
  14. Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
  15. if(true){
  16. extraFlagField.invoke(this.getWindow(),darkModeFlag,darkModeFlag);//状态栏透明且黑色字体
  17. }else{
  18. extraFlagField.invoke(this.getWindow(), 0, darkModeFlag);//清除黑色字体
  19. }
  20. }catch (Exception e){
  21.  
  22. }
  23. }
  24. @TargetApi(19)
  25. private void setTranslucentStatus(boolean on) {
  26. Window win = getWindow();
  27. WindowManager.LayoutParams winParams = win.getAttributes();
  28. final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
  29. if (on) {
  30. winParams.flags |= bits; // a|=b的意思就是把a和b按位或然后赋值给a 按位或的意思就是先把a和b都换成2进制,然后用或操作,相当于a=a|b
  31. } else {
  32. winParams.flags &= ~bits; //&是位运算里面,与运算 a&=b相当于 a = a&b ~非运算符
  33. }
  34. win.setAttributes(winParams);
  35. }

android 设置状态栏与标题背景颜色一致的更多相关文章

  1. android中在java代码中设置Button按钮的背景颜色

    android中在java代码中设置Button按钮的背景颜色 1.设置背景图片,图片来源于drawable: flightInfoPanel.setBackgroundDrawable(getRes ...

  2. Android中设置控件的背景颜色的方式整理

    版权声明:本文为博主原创文章,未经博主允许不得转载. 前言 在Android开发中,经常需要设置控件的背景颜色或者图片的src颜色. 效果图 代码分析 根据使用的方法不同,划分为 setBackgro ...

  3. android:改动PagerTabStrip中的背景颜色,标题字体的样式、颜色和图标以及指示条的颜色

    1.改动PagerTabStrip中的背景颜色 我们在布局中直接设置background属性就可以: <android.support.v4.view.ViewPager android:id= ...

  4. iOS平台设置系统状态栏(通知栏、顶部状态栏)样式背景颜色或透明

    5+App开发 状态栏 配置系统状态栏样式 iOS平台可支持对系统状态栏样式的配置,在应用manifest.json文件的plus->distribute->apple下添加UIStatu ...

  5. android:修改PagerTabStrip中的背景颜色,标题字体的样式、颜色和图标以及指示条的颜色

    1.修改PagerTabStrip中的背景颜色 我们在布局中直接设置background属性即可: <android.support.v4.view.ViewPager android:id=& ...

  6. android:theme决定AlertDialog的背景颜色

    最近遇到一个很奇怪的问题,两个项目弹出的dialog背景颜色不一样,一个是黑色的,一个是白色的,最后发现是AndroidManifest.xml文件里面application指定的android:th ...

  7. DevExpress.XtraGrid.Views 设置指定行的背景颜色 .

    如需要将指定行的背景设置颜色,可参考以下示例 1.事件:CustomDrawCell 2.示例: private void gridView1_CustomDrawCell(object sender ...

  8. iOS 8 设置导航栏的背景颜色和背景图片

    假设是storyboard 直接embed一个导航栏.然后在新出现的导航栏 选属性 选一下颜色就能够了 代码实现背景颜色改动:self.navigationController.navigationB ...

  9. Android设置状态栏颜色

    1.代码设置if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = this.getWindow ...

随机推荐

  1. Linux shell相关

    1 一些常见的问题及解决方法 <1> ssh登录不显示用户名跟路径 可能原因: ssh登录的用户没有配置shell 对应解决方案:在/etc/passwd文件对应用户那一行末尾添加/bin ...

  2. Laravel学习笔记(五)数据库 数据库迁移案例2——创建数据结构,数据表,修改数据结构

    默认假设 所有的列在定义的时候都有默认的假设,你可以根据需要重写. Laravel假定每个表都有一个数值型的主键(通常命名为”id”),确保新加入的每一行都是唯一的.Laravel只有在每个表都有数值 ...

  3. 使用delphi+intraweb进行微信开发3—微信消息处理

    示例代码已经放出!请移步使用delphi+intraweb进行微信开发1~4代码示例进行下载,虽为示例代码但是是从我项目中移出来的,封装很完备适于自行扩展和修改. 在第二讲使用delphi+intra ...

  4. php-建造者模式(Builder)解析

    其与抽象模式相类似,都可以创建复杂的对象,但是抽象工厂更注重多个系列的产品对象,而Builder模式则着重于一步一步的构建一个复杂的对象,在最后一步才返回产品, 使用建造者模式的好处是: 1.将构造代 ...

  5. iOS10 权限适配

    权限适配 这应该算iOS10系统适配的范畴,最近这两个都在弄,所以就直接和Xcode8适配一起写出来了. 在iOS10之后需要在Info.plist中,添加新的字段获取权限,否则在iOS10上运行会导 ...

  6. xcode 8   去除无用打印信息

    更新Xcode8之后,控制台会默认打印一坨东西,屏蔽的方法如下:Xcode8里边 Edit Scheme-> Run -> Arguments, 在Environment Variable ...

  7. JS中offsetTop、clientTop、scrollTop、offsetTop各属性介绍

    这里是javascript中制作滚动代码的常用属性 页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见 ...

  8. golang在linux下的开发环境部署[未完]

    uname -a Linux symons_laptop 4.8.2-1-ARCH #1 SMP PREEMPT Mon Oct 17 08:11:46 CEST 2016 x86_64 GNU/Li ...

  9. SequoiaDB 笔记

    SequoiaDB 笔记 这几天翻了翻SequoiaDB的代码,记了点笔记.不保证下面内容的正确性(肯定有错的地方) 个人观感 优点 代码还不错,设计也算简洁. EDU和CB的使用让整个系统变得简单很 ...

  10. WebServices(转)

    一.序言 大家或多或少都听过WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成分.但是不得不承认的是Web ...