我正在使用来自
Android设计支持库和工具栏的NavigationView,一切正常,但我想知道如何让汉堡图标变暗(现在它显得很白).此外,我想调整从屏幕边缘到ActionBar标题的距离.那我该怎么做?感谢帮助.
我将主题设置为Theme.AppCompat.Light.NoActionBar.所以我使用工具栏.这是我的代码:
public class MainActivity extends AppCompatActivity { //Defining Variables private Toolbar toolbar; private NavigationView navigationView; private DrawerLayout drawerLayout; ViewPager pager; ViewPagerAdapter adapter; SlidingTabLayout tabs; CharSequence Titles[]={"Песни","Исполнители"}; int Numboftabs =2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initializing Toolbar and setting it as the actionbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);
和xml:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="false" tools:context=".MainActivity"> <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" > <include android:id="@+id/toolbar" layout="@layout/tool_bar" /> <ru.amdm.amdm.SlidingTabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="2dp" android:background="@color/ColorPrimary"/> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:foreground="?android:windowContentOverlay"> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_height="match_parent" android:layout_width="match_parent"/> </FrameLayout> </LinearLayout> <android.support.design.widget.NavigationView android:id="@+id/navigation_view" android:layout_height="match_parent" android:layout_width="wrap_content" android:layout_gravity="start" app:headerLayout="@layout/header" app:menu="@menu/drawer" />
解决方法
要更改汉堡图标,只需创建一个新图标(例如ic_my_dark_menu),然后将其分配给您的操作栏:
actionBar.setHomeAsUpIndicator(R.drawable.ic_my_dark_menu);
或者,如果你愿意这样做,你可以tint你现有的图标:
Drawable drawable = ResourcesCompat.getDrawable(getResources(),R.drawable.ic_menu,null); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable,Color.BLACK); actionBar.setHomeAsUpIndicator(drawable);
要更改操作栏标题和边缘之间的空间量,只需编辑工具栏布局(res / layout / tool_bar.xml).例如,您可以像这样添加填充:
RES /布局/ tool_bar.xlml
<android.support.v7.widget.Toolbar ... android:paddingTop="16dp" />