最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 自定義狀態(tài)欄實例代碼

 更新時間:2017年02月15日 08:52:08   投稿:mrr  
本文通過實例代碼給大家講解了Android 自定義狀態(tài)欄知識,非常不錯,具有參考借鑒價值,需要的朋友參考下

一、目標:Android5.0以上

二、步驟

1、在res-values-colors.xml下新建一個RGB顏色

  <?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,在后邊重寫布局時用于添加

<?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布局,放置步驟二新建的布局在頂部,用作背景顏色的容器

  public class ActionBarLayOut extends LinearLayout { 
    public ActionBarLayOut(Context context, AttributeSet attrs){ 
      super(context,attrs); 
      LayoutInflater.from(context).inflate(R.layout.actionbarlayout,this); 
    } 
  }

3、在主布局里調(diào)用這個重寫后的線性布局

<?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活動中進行相應設(shè)置

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(); 
      } 
      //------------------------------------------------------------------------------------------ 
      //----------------------------------將狀態(tài)欄設(shè)置為透明-------------------------------------- 
      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); 
      } 
      //------------------------------------------------------------------------------------------ 
      /** 
       * 首先獲取狀態(tài)欄的高度statusBarHeight1,然后在狀態(tài)欄的位置放一個空的TextView, 
       * 高度設(shè)置為statusBarHeight1,然后將TextView的背景顏色進行設(shè)置,這樣就可以變相 
       * 的給狀態(tài)欄設(shè)置顏色 
       */ 
      int statusBarHeight1 = -1; 
      //獲取status_bar_height資源的ID 
      int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); 
      if (resourceId > 0) { 
        //根據(jù)資源ID獲取響應的尺寸值 
        statusBarHeight1 = getResources().getDimensionPixelSize(resourceId); 
      } 
      textView.setHeight(statusBarHeight1); 
      textView.setBackgroundColor(ActionBarColor); 
    } 
  } 

以上所述是小編給大家介紹的Android 自定義狀態(tài)欄實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

上蔡县| 江阴市| 灯塔市| 黄平县| 慈利县| 宝兴县| 同德县| 翁源县| 亚东县| 博客| 宝山区| 酉阳| 城口县| 封丘县| 八宿县| 高碑店市| 潮州市| 南江县| 五河县| 蒙自县| 板桥市| 砀山县| 色达县| 高邮市| 阿拉善左旗| 五河县| 法库县| 广昌县| 蚌埠市| 广州市| 腾冲县| 青浦区| 原阳县| 抚州市| 兴义市| 屏南县| 石首市| 永城市| 青冈县| 综艺| 威远县|