欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

一、目標(biāo):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活動中進行相應(yīng)設(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){ 
      //----------------------------------隱藏標(biāo)題欄---------------------------------------------- 
      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獲取響應(yīng)的尺寸值 
        statusBarHeight1 = getResources().getDimensionPixelSize(resourceId); 
      } 
      textView.setHeight(statusBarHeight1); 
      textView.setBackgroundColor(ActionBarColor); 
    } 
  } 

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

相關(guān)文章

  • Android UI繪制流程及原理詳解

    Android UI繪制流程及原理詳解

    在本篇文章里小編給大家整理的是關(guān)于Android UI繪制流程及原理以及相關(guān)知識點,需要的朋友們可以學(xué)習(xí)下。
    2019-08-08
  • Android添加用戶組及自定義App權(quán)限的方法

    Android添加用戶組及自定義App權(quán)限的方法

    今天小編就為大家分享一篇Android添加用戶組及自定義App權(quán)限的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • Android?Jetpack?Compose開發(fā)實用小技巧

    Android?Jetpack?Compose開發(fā)實用小技巧

    這篇文章主要為大家介紹了Android?Jetpack?Compose開發(fā)中的一些實用小技巧示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • 在Flutter中正確處理文本縮放的解決方案

    在Flutter中正確處理文本縮放的解決方案

    這篇文章主要介紹了在Flutter中正確處理文本縮放的解決方案,本教程的結(jié)構(gòu)首先介紹最簡單且最有影響力的解決方案,后面的部分涵蓋了較難實施且總體影響較小的解決方案,但它們對于解決特定情況很有用,需要的朋友可以參考下
    2024-06-06
  • Android開發(fā)筆記 最好使用eclipse

    Android開發(fā)筆記 最好使用eclipse

    值得注意一點的是,雖然Myeclipse比eclipse功能更強大,但是在具體的安卓開發(fā)過程當(dāng)中,最好還是選用eclipse,sdk跟eclipse的兼容性更好
    2012-11-11
  • Android自定義View的實現(xiàn)方法實例詳解

    Android自定義View的實現(xiàn)方法實例詳解

    本文通過實例代碼給大家詳細介紹了Android自定義View的實現(xiàn)方法,需要的朋友可以參考下
    2017-09-09
  • Android退出應(yīng)用最優(yōu)雅的方式(改進版)

    Android退出應(yīng)用最優(yōu)雅的方式(改進版)

    這篇文章主要介紹了Android退出應(yīng)用最優(yōu)雅的方式,改進版,感興趣的小伙伴們可以參考一下
    2016-01-01
  • Android入門之Service的使用詳解

    Android入門之Service的使用詳解

    我們的Android在啟動一些長事務(wù)時都會使用異步,很多初學(xué)者覺得這個異步就是一個異步線程+Handler而己。如果你這么想就錯了。這一切其實靠的正是Android里的Service。本文就來和大家聊聊Service的生命周期和使用,需要的可以參考一下
    2022-12-12
  • Android EditText密碼的隱藏和顯示功能

    Android EditText密碼的隱藏和顯示功能

    這篇文章主要介紹了Android EditText密碼的隱藏和顯示功能的相關(guān)資料,主要是利用EditText和CheckBox 來實現(xiàn)該功能,需要的朋友可以參考下
    2017-07-07
  • android實現(xiàn)手機App實現(xiàn)拍照功能示例

    android實現(xiàn)手機App實現(xiàn)拍照功能示例

    本篇文章主要介紹了android實現(xiàn)手機App實現(xiàn)拍照功能示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-02-02

最新評論