1

如图所示,我想删除菜单图标顶部的多余空间。您可以看到手形菜单图标(标记为绿色)和状态栏之间有很大的空间。

在这些标题、导航图标和菜单图标的顶部有一个烦人的空间!我怎样才能删除它?

在此处输入图像描述

我的样式文件位于 values 文件夹中

<resources>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat">
    <item name="colorPrimary">#9c27b0</item>
    <item name="colorPrimaryDark">#9c27b0</item>
    <item name="android:windowNoTitle">false</item>
    <item name="windowActionBar">false</item>
    <item name="toolbarStyle">@style/myToolbarStyle</item>
    <item name="toolbarNavigationButtonStyle">@style/myToolbarNavigationButtonStyle</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>

</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/white</item>
</style>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">#9c27b0</item>
</style>
<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
</style>
<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">#673AB7</item>
    <item name="colorPrimaryDark">#512DA8</item>
    <item name="colorAccent">#FF4081</item>
    <item name="android:windowBackground">@color/window_background</item>
</style>
<style name="myToolbarNavigationButtonStyle" parent="@style/Widget.AppCompat.Toolbar.Button.Navigation">
    <item name="android:minWidth">0dp</item>
    <item name="android:padding">1dp</item>
    <item name="android:scaleType">centerInside</item>
</style>





<style name="myToolbarStyle" parent="@style/Widget.AppCompat.Toolbar">
    <item name="android:paddingRight">0dp</item>
    <item name="android:showDividers"> beginning</item>
    <item name="android:actionButtonStyle">@android:style/MediaButton</item>
    <item name="android:menuCategory">alternative</item>
</style>

在我的清单中

 <application
    android:allowBackup="true"
    android:largeHeap="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="com.dropbox.client2.android.AuthActivity"
        android:launchMode="singleTask"
        android:configChanges="orientation|keyboard">
        <intent-filter>
            <data android:scheme="db-urxtj5jnxoix773" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name=".ComplexHeaderDrawerActivity"
        android:theme="@style/MaterialDrawerTheme">
    </activity>
    <activity android:name=".MainActivity">
    </activity>
    <activity android:name=".DropBoxActivity">

    </activity>
    <activity android:name=".SignInScreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

我的活动代码

public class ComplexHeaderDrawerActivity extends AppCompatActivity  {
    private static final int PROFILE_SETTING = 1;
    private AccountHeader headerResult = null;
    private Drawer result = null;
    private IProfile profile;
    ViewPager pager1;
    TextView tv;
    //private String titles0[]  = new String[]{"Home","Delivery", "Graph 1", "Downtime", "Graph 2", "Graph 3","Home","Delivery", "Graph 1", "Downtime", "Graph 2", "Graph 3"};
    private String titles0[]  = new String[]{"HOME","DELIVERY", "GRAPH 1", "DOWNTIME", "GRAPH 2", "GRAPH 3"};
    SlidingTabLayout slidingTabLayout;
    private static final int TIME_INTERVAL = 2000; // # milliseconds, desired time passed between two back presses.
    private long mBackPressed;
    String account;
    DatabaseHelper db;
    Integer[] keysarr;
    Set<Integer> keys;
    String sqlitesynctime="",yesterday="";
    Date date;
    String processedsynctime;
    Bitmap myBitmap;
    private Menu menu;

   // SharedPreferences pref;
   // SharedPreferences.Editor editor;
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sample);
        db= new DatabaseHelper(getApplicationContext());
        db.getReadableDatabase();
        View decorView = getWindow().getDecorView();

        //pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode        editor = pref.edit();
        //editor=pref.edit();
        //editor.putBoolean("isfirsttime", false);
        //editor.commit();
        // Hide the status bar.
//        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
//                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
//                | View.SYSTEM_UI_FLAG_FULLSCREEN
//                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        sqlitesynctime=db.getlastsyncedtime(); // "2015-06-27 12:56:36";

        if(sqlitesynctime.equals(null)){
            SimpleDateFormat mFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = new Date();
            sqlitesynctime= mFormatter.format(date);
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            date = sdf.parse(sqlitesynctime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Date dateBefore = new Date(date.getTime() - 1 * 24 * 3600 * 1000l);
        yesterday = sdf.format(dateBefore);
        Log.d("dssssssgh",""+sqlitesynctime+" - - "+yesterday);
        Log.d("servertimedb",sqlitesynctime+"yesterday - - ->"+yesterday);

        SimpleDateFormat pst = new SimpleDateFormat("MMMM dd, yyyy hh:mm aa");

        processedsynctime=pst.format(date);
        pager1 = (ViewPager) findViewById(R.id.viewpager1);
        slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
        tv=(TextView)findViewById(R.id.tv);
        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitleTextColor(Color.parseColor("#ffffffff"));

        setSupportActionBar(toolbar);
        toolbar.setBackgroundColor(Color.parseColor("#ffFD5854"));
        //toolbar.setBackgroundColor(Color.parseColor("#ffE74C3C"));
        toolbar.animate();

//        toolbar.setLayoutParams(new LinearLayout.LayoutParams(
//                ViewGroup.LayoutParams.MATCH_PARENT,
//                156,
//                Gravity.TOP | Gravity.RIGHT));
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.menu_1:
//update the profile2 and set a new image.
                        // profile2.setIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_android).backgroundColorRes(R.color.accent).sizeDp(48).paddingDp(4));
                        // headerResult.updateProfileByIdentifier(profile2);
                        // Toast.makeText(getApplicationContext(),"ff"+item.getItemId(),Toast.LENGTH_SHORT).show();
                       // Toast.makeText(getApplicationContext(), "done", Toast.LENGTH_SHORT).show();
                        pager1.setCurrentItem(0);
                        return true;
                    case R.id.menu_2:
//show the arrow icon
                        //result.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false);
                        //getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                        ///toolbar.setVisibility(View.GONE);
                        return true;

                    default:
                }
                return true;
            }
        });

        File imgFile = new  File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Datamark/AppFiles/myprofilepicture.jpg");
        if(imgFile.exists()){
            myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
        }
        else {
            myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.profile);
        }
////        setSupportActionBar(toolbar);
        account = account();
       // emailaccount.setText(account);
        profile = new ProfileDrawerItem().withName("Aravind U").withEmail(account).withIcon(myBitmap);
        pager1.setVisibility(View.VISIBLE);
        pager1.setAdapter(new ViewPagerAdapter1(getSupportFragmentManager(), titles0, 2));
        slidingTabLayout.setViewPager(pager1);




        //bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff9c27b0")));
        //final Map<Integer, String> myMap= db.getprojects("juandroidapp@gmail.com");
        final Map<Integer, String> myMap= db.getprojects(account);
        keys = myMap.keySet();
        keysarr= keys.toArray(new Integer[keys.size()]);
        final List<String> list = new ArrayList<String>();
        Iterator<Map.Entry<Integer,String>> iterator = myMap.entrySet().iterator();
        Map.Entry<Integer,String> entry;
        while(iterator.hasNext()){
            entry = iterator.next();
            Log.d("Key Value",entry.getKey()+" "+entry.getValue());
            list.add(entry.getValue());
        }
        final FontAwesome.Icon[] icons={FontAwesome.Icon.faw_database,FontAwesome.Icon.faw_adjust,FontAwesome.Icon.faw_android,FontAwesome.Icon.faw_bar_chart,FontAwesome.Icon.faw_arrow_down,FontAwesome.Icon.faw_automobile,FontAwesome.Icon.faw_arrow_circle_up,FontAwesome.Icon.faw_behance_square,FontAwesome.Icon.faw_bell,FontAwesome.Icon.faw_certificate,FontAwesome.Icon.faw_car,FontAwesome.Icon.faw_cc_visa,FontAwesome.Icon.faw_check_circle,FontAwesome.Icon.faw_cc_discover,FontAwesome.Icon.faw_soundcloud,FontAwesome.Icon.faw_tasks,FontAwesome.Icon.faw_sort_desc,FontAwesome.Icon.faw_share_square_o,FontAwesome.Icon.faw_angle_double_down,FontAwesome.Icon.faw_compass,FontAwesome.Icon.faw_mars_stroke_v,FontAwesome.Icon.faw_vimeo_square,FontAwesome.Icon.faw_coffee,FontAwesome.Icon.faw_anchor,FontAwesome.Icon.faw_soccer_ball_o,FontAwesome.Icon.faw_asterisk,FontAwesome.Icon.faw_chevron_circle_right,FontAwesome.Icon.faw_pencil};// new FontAwesome.Icon[]{};
        final int [] iconimages={R.drawable.database_32,
                R.drawable.contrast_icon_64,
                R.drawable.android_logo_64,
                R.drawable.four_bars_graph,
                R.drawable.arrow_down_64,
                R.drawable.four_bars_graph,
                R.drawable.contrast_icon_64,
                R.drawable.android_logo_64,
                R.drawable.four_bars_graph,
                R.drawable.arrow_down_64,
                R.drawable.four_bars_graph};
        SecondaryDrawerItem[] myitem = new SecondaryDrawerItem[myMap.size()];
        //  {
        for (int m = 0; list.size() > m; m++) {
            myitem[m] = new SecondaryDrawerItem().withName(list.get(m)).withIcon(icons[m]);
        }
//int g=list.size()+1;
         //   myitem[g]= new SectionDrawerItem().withName(R.string.drawer_item_section_header)
        //}
        result = new DrawerBuilder()
                .withTranslucentStatusBar(false)
                .withActivity(this)
                .withToolbar(toolbar)
                .withActionBarDrawerToggleAnimated(true)
                .withRootView(R.id.drawer_container)
                .withAccountHeader(headerResult)
                .addDrawerItems(
                        myitem
                        //new SecondaryDrawerItem().withName("temp").withIcon(FontAwesome.Icon.faw_database)
                )
//                            // add the items we want to use with our Drawer
                .withOnDrawerNavigationListener(new Drawer.OnDrawerNavigationListener() {
                    @Override
                    public boolean onNavigationClickListener(View clickedView) {
//this method is only called if the Arrow icon is shown. The hamburger is automatically managed by the MaterialDrawer
//                            //if the back arrow is shown. close the activity
                        ComplexHeaderDrawerActivity.this.finish();
                        //return true if we have consumed the event
                        return true;
                    }
                })
                .addStickyDrawerItems(
                        //  new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog).withIdentifier(10),
                        //new SecondaryDrawerItem().withName("Sync Now").withIcon(FontAwesome.Icon.faw_cog).withIdentifier(10)
                        new SectionDrawerItem().withName("Last Sync: "+processedsynctime)
                        //new SectionDrawerItem().withName(processedsynctime)
                        //new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github)
                )
                .withAnimateDrawerItems(true)
                .withSavedInstance(savedInstanceState)
                .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                    @Override
                    public boolean onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) {

                        tv.setText(list.get(position));
                        pager1.setAdapter(new ViewPagerAdapter1(getSupportFragmentManager(), titles0, keysarr[position]));
                        slidingTabLayout.setViewPager(pager1);

                        //menu.findItem(R.id.menu_2).setIcon(iconimages[position]);
                        menu.findItem(R.id.menu_1).setIcon(iconimages[position]);
                        return false;
                    }
                }).build();

//            new DrawerBuilder()
//                    .withActivity(this)
//                    //.withFooter(R.layout.footer)
//                   // .withDisplayBelowStatusBar(true)
//                    .addDrawerItems(
//                            new DividerDrawerItem(),
//                            new SectionDrawerItem().withName(R.string.drawer_item_section_header),
//                            new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)
//                    )
//                    .withDrawerGravity(Gravity.END)
//                    .append(result);
        slidingTabLayout.setBackgroundColor(Color.parseColor("#ffFD5854")); //ab47bc //9c27b0
        //slidingTabLayout.setBackgroundColor(Color.parseColor("#ffFD5B68")); //ab47bc //9c27b0
        //slidingTabLayout.setBackgroundColor(Color.parseColor("#ffE74C3C")); //ab47bc //9c27b0
        slidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
            @Override
            public int getIndicatorColor(int position) {
                return Color.parseColor("#ff9A34A2");
            }
        });



        buildHeader(true, null);


        result.setHeader(headerResult.getView());correctly)
        headerResult.setDrawer(result);

        String responsetxt = getLcfieldText();
         if(responsetxt.equals("syncnow")){
             Intent intent3 = new Intent(ComplexHeaderDrawerActivity.this, MainActivity.class);
             intent3.putExtra("sqlitesynctime",sqlitesynctime);
             startActivity(intent3);
            Toast.makeText(getApplicationContext(),"New data available syncing started..",Toast.LENGTH_SHORT).show();
        }else if(responsetxt.equals("justupdated")) {
            Toast.makeText(getApplicationContext(),"Showing the lastest data.. Last updated time :"+processedsynctime,Toast.LENGTH_SHORT).show();
         }else{
             Toast.makeText(getApplicationContext(),"There is a error! Please contact processteam.",Toast.LENGTH_SHORT).show();
         }

         }

    public void buildHeader(boolean compact, Bundle savedInstanceState) {
        // Create the AccountHeader
        headerResult = new AccountHeaderBuilder()
                .withActivity(this)
                .withHeaderBackground(R.drawable.header)
                .withCompactStyle(compact)
                .addProfiles(
                        profile
                )
                .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
                    @Override
                    public boolean onProfileChanged(View view, IProfile profile, boolean current) {
                        //sample usage of the onProfileChanged listener
                        //if the clicked item has the identifier 1 add a new profile ;)
                        if (profile instanceof IDrawerItem && ((IDrawerItem) profile).getIdentifier() == PROFILE_SETTING) {
                            IProfile newProfile = new ProfileDrawerItem().withNameShown(true).withName("Batman").withEmail("batman@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile5));
                            if (headerResult.getProfiles() != null) {
                                //we know that there are 2 setting elements. set the new profile above them ;)
                                headerResult.addProfile(newProfile, headerResult.getProfiles().size() - 2);
                            } else {
                                headerResult.addProfiles(newProfile);
                            }
                        }
                        //false if you have not consumed the event and it should close the drawer
                        return false;
                    }
                })
                .withSavedInstance(savedInstanceState)
                .build();
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        this.menu = menu;



       /* menu.add(Menu.NONE, 0, Menu.NONE, "custom")
                .setActionView(R.layout.test)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);*/

        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
//        if (mDrawerToggle.onOptionsItemSelected(item)) {
//            return true;
//        }
        // Handle your other action bar items...
        return super.onOptionsItemSelected(item);
    }
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        //add the values which need to be saved from the drawer to the bundle
        outState = result.saveInstanceState(outState);
        //add the values which need to be saved from the accountHeader to the bundle
        outState = headerResult.saveInstanceState(outState);
        super.onSaveInstanceState(outState);
    }
    @Override
    public void onBackPressed()
    {
        if (result != null && result.isDrawerOpen()) {
            result.closeDrawer();
        } else {
            if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) {
                super.onBackPressed();
                return;
            } else {
                Toast.makeText(getBaseContext(),"Tap back button again to exit", Toast.LENGTH_SHORT).show();
            }
            mBackPressed = System.currentTimeMillis();
        }
    }

}

我知道这段代码很乱!请原谅我!

4

0 回答 0