如何将工具栏透明用作动作栏,如下面的截图?

时间:2016-06-05 18:12:01

标签: android android-actionbar toolbar

enter image description here

     public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener {

private static String TAG = MainActivity.class.getSimpleName();

private Toolbar mToolbar;
private FragmentDrawer drawerFragment;

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

    mToolbar = (Toolbar) findViewById(R.id.toolbar);

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    drawerFragment = (FragmentDrawer)
            getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
    drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
    drawerFragment.setDrawerListener(this);

    // display the first navigation drawer view on app launch
    displayView(0);
}

工具栏

    <?xml version="1.0" encoding="utf-8"?>
   <android.support.v7.widget.Toolbar      xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

我想把图像像cureent play app。 我正在使用此链接示例来实现此目的  http://www.androidhive.info/2015/04/android-getting-started-with-material-design/

请帮忙 提前谢谢。

1 个答案:

答案 0 :(得分:0)

作为此链接的参考 http://blog.raffaeu.com/archive/2015/04/11/android-and-the-transparent-status-bar.aspx

通过在Styles.xml和样式(v21).xml中使用以下XML属性很容易实现:

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