android – 如何更改ActionBar汉堡包图标的颜色?

前端之家收集整理的这篇文章主要介绍了android – 如何更改ActionBar汉堡包图标的颜色?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用来自 Android设计支持库和工具栏的NavigationView,一切正常,但我想知道如何让汉堡图标变暗(现在它显得很白).此外,我想调整从屏幕边缘到ActionBar标题的距离.那我该怎么做?感谢帮助.

我将主题设置为Theme.AppCompat.Light.NoActionBar.所以我使用工具栏.这是我的代码

  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. //Defining Variables
  4. private Toolbar toolbar;
  5. private NavigationView navigationView;
  6. private DrawerLayout drawerLayout;
  7. ViewPager pager;
  8. ViewPagerAdapter adapter;
  9. SlidingTabLayout tabs;
  10. CharSequence Titles[]={"Песни","Исполнители"};
  11. int Numboftabs =2;
  12.  
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.activity_main);
  17.  
  18. // Initializing Toolbar and setting it as the actionbar
  19. toolbar = (Toolbar) findViewById(R.id.toolbar);
  20. setSupportActionBar(toolbar);

和xml:

  1. <android.support.v4.widget.DrawerLayout
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. xmlns:app="http://schemas.android.com/apk/res-auto"
  5. android:id="@+id/drawer"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8. android:fitsSystemWindows="false"
  9. tools:context=".MainActivity">
  10.  
  11. <LinearLayout
  12. android:layout_height="match_parent"
  13. android:layout_width="match_parent"
  14. android:orientation="vertical"
  15. >
  16. <include
  17. android:id="@+id/toolbar"
  18. layout="@layout/tool_bar"
  19. />
  20.  
  21. <ru.amdm.amdm.SlidingTabLayout
  22. android:id="@+id/tabs"
  23. android:layout_width="match_parent"
  24. android:layout_height="wrap_content"
  25. android:elevation="2dp"
  26. android:background="@color/ColorPrimary"/>
  27.  
  28. <FrameLayout
  29. android:layout_width="match_parent"
  30. android:layout_height="match_parent"
  31. android:foreground="?android:windowContentOverlay">
  32.  
  33. <android.support.v4.view.ViewPager
  34. android:id="@+id/pager"
  35.  
  36. android:layout_height="match_parent"
  37. android:layout_width="match_parent"/>
  38. </FrameLayout>
  39.  
  40. </LinearLayout>
  41.  
  42. <android.support.design.widget.NavigationView
  43. android:id="@+id/navigation_view"
  44. android:layout_height="match_parent"
  45. android:layout_width="wrap_content"
  46. android:layout_gravity="start"
  47. app:headerLayout="@layout/header"
  48. app:menu="@menu/drawer"
  49. />

解决方法

要更改汉堡图标,只需创建一个新图标(例如ic_my_dark_menu),然后将其分配给您的操作栏:
  1. actionBar.setHomeAsUpIndicator(R.drawable.ic_my_dark_menu);

或者,如果你愿意这样做,你可以tint你现有的图标:

  1. Drawable drawable = ResourcesCompat.getDrawable(getResources(),R.drawable.ic_menu,null);
  2. drawable = DrawableCompat.wrap(drawable);
  3. DrawableCompat.setTint(drawable,Color.BLACK);
  4. actionBar.setHomeAsUpIndicator(drawable);

要更改操作栏标题和边缘之间的空间量,只需编辑工具栏布局(res / layout / tool_bar.xml).例如,您可以像这样添加填充:

RES /布局/ tool_bar.xlml

  1. <android.support.v7.widget.Toolbar
  2. ...
  3. android:paddingTop="16dp" />

猜你在找的Android相关文章