所以现在Android5.0已经发布了,我想知道如何对动画的actionbar图标进行样式设计。
对于我来说,这个库这里实现和样式都很好,但是既然appcompat 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>我把这个添加到我的风格中,但没有起作用。也添加到我的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 other -->
<attr name="gapBetweenBars" format="dimension"/>
<!-- The size of the top and bottom bars when they merge to the middle bar to form an arrow -->
<attr name="topBottomBarArrowSize" format="dimension"/>
<!-- The size of the middle bar when top and bottom bars merge into middle bar to form an arrow -->
<attr name="middleBarArrowSize" format="dimension"/>
<!-- The size of the bars when they are parallel to each other -->
<attr name="barSize" format="dimension"/>
<!-- The thickness (stroke size) for the bar paint -->
<attr name="thickness" format="dimension"/>
</declare-styleable>但是当这样做时,崩溃并表示颜色类型错误。我遗漏了什么?
发布于 2014-10-18 13:56:00
以下几点对我来说是可行的:
<style name="MyTheme" parent="Theme.AppCompat">
<item name="drawerArrowStyle">@style/MyDrawerArrowToggle</item>
</style>
<style name="MyDrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">@color/your_color</item>
</style>发布于 2015-02-11 09:16:55
在我的例子中,我想改变抽屉箭头和汉堡包图标的颜色。设置抽屉箭头样式只改变汉堡包图标的颜色。
因此,我在appcompat-v7的values.xml中打开了values.xml样式。
<style name="Widget.AppCompat.DrawerArrowToggle" parent="Base.Widget.AppCompat.DrawerArrowToggle">
<item name="color">?attr/colorControlNormal</item>
</style>所以我创造了一个特别的主题:
<style name="Toolbar_Theme">
<item name="colorControlNormal">@android:color/black</item>
</style>并将其应用于我的工具栏,如下所示:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
app:theme="@style/Toolbar_Theme" />请注意,我使用的是theme 属性,而不是在应用程序主题中定义controlColorNormal。这样,颜色将只适用于工具栏项目,如果我在应用程序主题中设置它,那么它也会影响滚动条的颜色等等。
设置colorControlNormal属性会改变汉堡包和抽屉箭头的颜色。
发布于 2015-08-19 17:13:29
对于任何最终在这里(像我一样)使用v7 ActionBarDrawerToggle用自己的可绘制(非动画)替换抽屉指示器图标的人,您可以执行以下操作:
//After instantiating your ActionBarDrawerToggle
mDrawerToggle.setDrawerIndicatorEnabled(false);
Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.your_custom_icon, getActivity().getTheme());
mDrawerToggle.setHomeAsUpIndicator(drawable);
mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
mDrawerLayout.openDrawer(GravityCompat.START);
}
}
});https://stackoverflow.com/questions/26439572
复制相似问题