2015-12-20 36 views

回答

0

步驟1中給出的截圖應用程序欄應用程序欄:第一對於你需要如下創建一個主題:

<!-- Make the status bar traslucent --> 
    <style name="AppTheme" parent="AppTheme.Base"> 
     <item name="android:windowTranslucentStatus">true</item> 
    </style> 

第2步:製作方法,它會得到Status bar高度:

public int getStatusBarHeight() { 
    int result = 0; 
    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); 
    if (resourceId > 0) { 
     result = getResources().getDimensionPixelSize(resourceId); 
    } 
    return result; 
} 

第3步:呼叫從ActivityonCreate()方法的方法和改變Status bar的顏色,你的願望:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_drawer); 

     // Retrieve the AppCompact Toolbar 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     // Set the padding to match the Status Bar height 
     toolbar.setPadding(0, getStatusBarHeight(), 0, 0); 

     // create our manager instance after the content view is set 
     SystemBarTintManager tintManager = new SystemBarTintManager(this); 
    // enable status bar tint 
     tintManager.setStatusBarTintEnabled(true); 
    // enable navigation bar tint 
     tintManager.setNavigationBarTintEnabled(true); 
    // set the transparent color of the status bar, 20% darker 
     tintManager.setTintColor(Color.parseColor("#20000000")); 
    } 

按照上面的步驟,你會得到你的狀態欄透明和你可以添加圖像或顏色到背景。