我在新的材料设计Side Nav规范中看到,您可以在操作栏上和状态栏后面显示抽屉.我该如何实现呢?
我使用android.support.v7.widget.Toolbar与android.support.v4.widget.DrawerLayout.它工作正常,导航抽屉关闭时显示汉堡图标,抽屉打开时显示箭头图标.我想在应用程序中的某些事件中禁用抽屉并将Burger图标设置为箭头.我试图将锁定模式设置为关闭,但v7.app.ActionBarDrawerToggle仍显示Burger并打开抽屉.
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
有任何想法吗?谢谢!
更新:
不,我可以更改图标的状态,我可以启用/禁用抽屉,但动画不能使用此方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
Toolbar toolbar = (Toolbar) findViewById(R.id.application_toolbar);
setSupportActionBar(toolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.string1, R.string.string2) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
//mDrawerLayout.setDrawerListener(mDrawerToggle); // not needed
...
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (mDrawerLayout.getDrawerLockMode(GravityCompat.START) == LOCK_MODE_UNLOCKED) {
showDrawer();
} else {
handleBackButtonPress(); // On this stage the home button is …Run Code Online (Sandbox Code Playgroud) 所以现在Android 5.0发布了,我想知道如何设置动画操作栏图标的样式.
该库在这里实现和风格也对我很好,但由于程序兼容性V7库有它怎么能称呼?
我使用v7 DrawerToggle实现了这个功能.但是我无法设计它.请帮忙
我在v7 styles_base.xml中找到了它的样式
<style name="Base.Widget.AppCompat.DrawerArrowToggle" parent="">
<item name="color">?android:attr/textColorSecondary</item>
<item name="thickness">2dp</item>
<item name="barSize">18dp</item>
<item name="gapBetweenBars">3dp</item>
<item name="topBottomBarArrowSize">11.31dp</item>
<item name="middleBarArrowSize">16dp</item>
<item name="drawableSize">24dp</item>
<item name="spinBars">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我把它添加到我的样式中并且没有用.也添加到我的attr.xml
<declare-styleable name="DrawerArrowToggle">
<!-- The drawing color for the bars -->
<attr name="color" format="color"/>
<!-- Whether bars should rotate or not during transition -->
<attr name="spinBars" format="boolean"/>
<!-- The total size of the drawable -->
<attr name="drawableSize" format="dimension"/>
<!-- The max gap between the bars when they are parallel to each …Run Code Online (Sandbox Code Playgroud) 我正在努力DrawerLayout搞动画做奇怪的事情; 该汉堡包图标是laggy,往往从汉堡包切换,而动画箭头,如果我不把一个处理器延迟fragment交易的动画.
所以我最终放了一个处理程序,等到汉堡包图标执行动画,但我们不需要等到抽屉接近切换片段就感觉不自然了.我确信有更好的方法可以解决这个问题......
这是我目前的做法:
private void selectProfilFragment() {
final BackHandledFragment fragment;
// TODO test this again
Bundle bundle = new Bundle();
bundle.putString(FragmentUserProfile.USER_FIRST_NAME, user.getFirstname());
bundle.putString(FragmentUserProfile.USER_LAST_NAME, user.getLastname());
bundle.putString(FragmentUserProfile.USER_PICTURE, user.getProfilepic());
bundle.putString(FragmentUserProfile.USER_EMAIL, user.getEmail());
bundle.putBoolean(FragmentUserProfile.USER_SECURITY, user.getParameters().getSecuritymodule().equals("YES"));
fragment = new FragmentUserProfile();
fragment.setArguments(bundle);
mDrawerLayout.closeDrawer(mDrawerLinear);
new Handler().postDelayed(new Runnable() {
public void run() {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.pull_in_right, R.anim.push_out_left, R.anim.pull_in_left, R.anim.push_out_right);
ft.replace(R.id.content_frame, fragment)
.addToBackStack(fragment.getTagText())
.commitAllowingStateLoss();
}
}, 300);
}
Run Code Online (Sandbox Code Playgroud)
它仍然毛刺在之间一点点DrawerLayout的关闭和开启片段交易的动画.
这是我如何实现抽屉:
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerListChild.setAdapter(new DrawerListAdapter(this, R.layout.drawer_layout_item, mPlanTitles));
mDrawerListChild.setOnItemClickListener(new …Run Code Online (Sandbox Code Playgroud) 我在Android应用程序中使用导航抽屉,工作正常.
我想补充一些动画的打开和关闭的抽屉式导航栏.
动画:
1.Opening-Navigation Drawer显示箭头,隐藏汉堡包.
2.Closing-Again显示汉堡包,隐藏箭头.
打开和关闭它应该是旋转.我尝试了一些不工作的代码.
请有人帮我这样做.
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<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>
Run Code Online (Sandbox Code Playgroud)
我尝试了这个, 链接我提到
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
//for Navigation Bar
DrawerLayout drawerLayout;
ListView listView;
String[] drawerlist;
ActionBarDrawerToggle drawerListener;
private MyAdapter4 myAdapter4;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.alerts);
//navigation initialize
drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
listView = (ListView) findViewById(R.id.drawerList);
drawerlist …Run Code Online (Sandbox Code Playgroud) 这是我的所有相关代码:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("sometitle");
toolbar.inflateMenu(R.menu.menu_main);
setSupportActionBar(toolbar);
Run Code Online (Sandbox Code Playgroud)
样式:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/sunshine_blue</item>
<item name="colorPrimaryDark">@color/sunshine_dark_blue</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="windowActionBar">false</item> <!-- Remove the default action bar -->
<item name="windowNoTitle">true</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
XML:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Replace the default action bar -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:elevation="5dp"
android:background="?attr/colorPrimary" />
<!-- The main content view -->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/fragment"
android:name="com.***.***.***.MainActivityFragment"
tools:layout="@layout/fragment_main" android:layout_width="match_parent"
android:layout_height="match_parent" …Run Code Online (Sandbox Code Playgroud)