带有选项卡的导航抽屉和工具栏

里亚科

伙计们,我的错误很简单。

我正在实现一个自定义工具栏(如操作栏)和Android应用程序,并实现一个导航抽屉。

问题是我使用的是材料设计主题,因此导航抽屉从状态栏后面的屏幕顶部开始,并占据所有屏幕高度,但是如果我这样做,则主要活动中的所有按钮和选项卡,无法明确显示,导致导航抽屉的高度为7dp,操作栏的高度为4。我该如何解决?还有一个问题,当显示导航抽屉时,如何使状态栏稍微透明并使背景变暗?

我想做到这一点,让我的标签可点击:

在此处输入图片说明

Main.java

    package com.saturdaynight;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;


public class Main extends ActionBarActivity {
    Toolbar toolbar;
    ViewPager pager;
    ViewPagerAdapter adapter;
    SlidingTabLayout tabs;
    CharSequence Titles[]={"Home","Events"};
    int Numboftabs =2;

    String TITLES[] = {"Home", "Events", "Mail", "Shop"};
    int ICONS[] = {R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher};

    String NAME = "Akash Bangad";
    String EMAIL = "[email protected]";
    int PROFILE = R.mipmap.ic_launcher;

    RecyclerView mRecyclerView;                           // Declaring RecyclerView
    RecyclerView.Adapter mAdapter;                        // Declaring Adapter For Recycler View
    RecyclerView.LayoutManager mLayoutManager;            // Declaring Layout Manager as a linear layout manager
    DrawerLayout Drawer;                                  // Declaring DrawerLayout

    ActionBarDrawerToggle mDrawerToggle;

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

        Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar); // Attaching the layout to the toolbar object
        if (toolbar != null) {
            setSupportActionBar(toolbar);
        }

        // Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
        adapter =  new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);

        // Assigning ViewPager View and setting the adapter
        pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(adapter);

        // Assiging the Sliding Tab Layout View
        tabs = (SlidingTabLayout) findViewById(R.id.tabs);
        tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width

        // Setting Custom Color for the Scroll bar indicator of the Tab View
        tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
            @Override
            public int getIndicatorColor(int position) {
                return getResources().getColor(R.color.tabsScrollColor);
            }
        });

        // Setting the ViewPager For the SlidingTabsLayout
        tabs.setViewPager(pager);


        mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

        mRecyclerView.setHasFixedSize(true);                            // Letting the system know that the list objects are of fixed size

        mAdapter = new MyAdapter(TITLES, ICONS, NAME, EMAIL, PROFILE);       // Creating the Adapter of MyAdapter class(which we are going to see in a bit)
        // And passing the titles,icons,header view name, header view email,
        // and header view profile picture

        mRecyclerView.setAdapter(mAdapter);                              // Setting the adapter to RecyclerView
        mLayoutManager = new LinearLayoutManager(this);                 // Creating a layout Manager
        mRecyclerView.setLayoutManager(mLayoutManager);                 // Setting the layout Manager

        Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);        // Drawer object Assigned to the view
        mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) {

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                invalidateOptionsMenu();
                // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is
                // open I am not going to put anything here)
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
                invalidateOptionsMenu();
                // Code here will execute once drawer is closed
            }


        }; // Drawer Toggle Object Made
        Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle
        mDrawerToggle.syncState();               // Finally we set the drawer toggle sync State

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

}

activity_main

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<include
    android:id="@+id/tool_bar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    layout="@layout/tool_bar"></include>


<com.saturdaynight.SlidingTabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:layout_marginTop="56dp"
    android:background="@color/ColorPrimary"
    android:elevation="4dp"
    android:layout_weight="1"/>

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"></android.support.v4.view.ViewPager>


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tool_bar"
    android:layout_marginTop="16dp"
    android:text="@string/hello_world" />

<android.support.v4.widget.DrawerLayout
    android:id="@+id/DrawerLayout"
    android:elevation="7sp"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView"
        android:layout_below="@+id/tabs"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:background="#fff"
        android:scrollbars="vertical">

    </android.support.v7.widget.RecyclerView>

</android.support.v4.widget.DrawerLayout>

`

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <item name="colorPrimary">@color/ColorPrimary</item>
        <item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
        <item name="windowActionModeOverlay">true</item>
        <item name="colorAccent">@color/ColorPrimary</item>
        <item name="android:windowContentTransitions">true</item>
        <item name="android:windowAllowEnterTransitionOverlap">true</item>
        <item name="android:windowAllowReturnTransitionOverlap">true</item>
        <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
        <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <!-- Customize your theme here. -->
    </style>
</resources>
机器人

显示导航抽屉时,如何使状态栏稍微透明并使背景变暗?

半透明系统栏

现在,您可以使用新主题Theme.Holo.NoActionBar.TranslucentDecorTheme.Holo.Light.NoActionBar.TranslucentDecor使系统栏部分透明通过启用半透明的系统栏,您的布局将填充系统栏后面的区域,因此,您还必须为布局的不应被系统栏覆盖的部分启用fitsSystemWindows。

如果要创建自定义主题,请将这些主题之一设置为父主题,或在主题中包含windowTranslucentNavigationwindowTranslucentStatus样式属性。

另外,在这里查看最佳答案:

https://stackoverflow.com/a/19733218/4945820

顺便说一句,当显示抽屉时,我认为背景将显示为深色。此外,如果您使用本教程*(来自-android4devs)*,则可以在显示抽屉后向您显示深色。

  • 使用 : <android.support.v4.widget.DrawerLayout

希望这可以帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

带有设计的工具栏的材料选项卡

来自分类Dev

Android工具栏选项卡导航

来自分类Dev

使用带有导航抽屉的ViewPager的操作栏选项卡

来自分类Dev

使用ViewPager和导航抽屉的操作栏选项卡

来自分类Dev

带有折叠工具栏的片段中的Android选项卡

来自分类Dev

带有折叠工具栏的片段中的Android选项卡

来自分类Dev

带有选项卡滑动的Android导航抽屉

来自分类Dev

Android工具栏选项卡

来自分类Dev

带有导航栏和工具栏的布局TableView

来自分类Dev

带有进度栏的引导导航选项卡

来自分类Dev

材质 UI 将抽屉和应用栏嵌套在带有选项卡的应用栏中

来自分类Dev

将工具栏添加到Google的导航抽屉示例中-带有测试代码和屏幕截图

来自分类Dev

在工具栏上使用滑动选项卡

来自分类Dev

在工具栏上使用滑动选项卡

来自分类Dev

带选项卡和抽屉导航的堆栈导航

来自分类Dev

片段和导航抽屉的不同工具栏

来自分类Dev

Android在单个活动中具有导航抽屉和工具栏

来自分类Dev

带有底部导航器选项卡的颤振抽屉

来自分类Dev

在主页 android xamarin 中带有选项卡的导航抽屉

来自分类Dev

正确使用导航抽屉和选项卡

来自分类Dev

底部导航栏,每个选项卡均带有子导航器

来自分类Dev

React Native-尝试在React导航中创建带有选项卡导航器的抽屉,而不渲染选项卡的Drawer项

来自分类Dev

带有Viewpager,选项卡和抽屉布局的片段容器不起作用

来自分类Dev

当片段显示在带有导航选项卡的操作栏中时,加载数据

来自分类Dev

在Shiny中添加带有各种顶级导航栏的链接面板选项卡

来自分类Dev

带有导航控制器的iOS TvOS选项卡栏

来自分类Dev

从导航抽屉中选择带有一些片段的滑动选项卡菜单项

来自分类Dev

如何在带有工具栏和底部导航视图的布局中使用滚动视图?

来自分类Dev

没有组件屏幕渲染的选项卡栏导航

Related 相关文章

  1. 1

    带有设计的工具栏的材料选项卡

  2. 2

    Android工具栏选项卡导航

  3. 3

    使用带有导航抽屉的ViewPager的操作栏选项卡

  4. 4

    使用ViewPager和导航抽屉的操作栏选项卡

  5. 5

    带有折叠工具栏的片段中的Android选项卡

  6. 6

    带有折叠工具栏的片段中的Android选项卡

  7. 7

    带有选项卡滑动的Android导航抽屉

  8. 8

    Android工具栏选项卡

  9. 9

    带有导航栏和工具栏的布局TableView

  10. 10

    带有进度栏的引导导航选项卡

  11. 11

    材质 UI 将抽屉和应用栏嵌套在带有选项卡的应用栏中

  12. 12

    将工具栏添加到Google的导航抽屉示例中-带有测试代码和屏幕截图

  13. 13

    在工具栏上使用滑动选项卡

  14. 14

    在工具栏上使用滑动选项卡

  15. 15

    带选项卡和抽屉导航的堆栈导航

  16. 16

    片段和导航抽屉的不同工具栏

  17. 17

    Android在单个活动中具有导航抽屉和工具栏

  18. 18

    带有底部导航器选项卡的颤振抽屉

  19. 19

    在主页 android xamarin 中带有选项卡的导航抽屉

  20. 20

    正确使用导航抽屉和选项卡

  21. 21

    底部导航栏,每个选项卡均带有子导航器

  22. 22

    React Native-尝试在React导航中创建带有选项卡导航器的抽屉,而不渲染选项卡的Drawer项

  23. 23

    带有Viewpager,选项卡和抽屉布局的片段容器不起作用

  24. 24

    当片段显示在带有导航选项卡的操作栏中时,加载数据

  25. 25

    在Shiny中添加带有各种顶级导航栏的链接面板选项卡

  26. 26

    带有导航控制器的iOS TvOS选项卡栏

  27. 27

    从导航抽屉中选择带有一些片段的滑动选项卡菜单项

  28. 28

    如何在带有工具栏和底部导航视图的布局中使用滚动视图?

  29. 29

    没有组件屏幕渲染的选项卡栏导航

热门标签

归档