问题描述
我试图改变样式属性colorControlNormal我的应用程序programmaticaly和运行过程中,但我没有任何结果。
I'm trying to change the style attribute "colorControlNormal" of my app programmaticaly and during runtime, but I didn't have any results.
这属性是将着色汉堡包和放大器的颜色;新的工具栏的ViewGroup回图标。除此之外,我使用的是V7的兼容性库。
This property is the color that will tint the hamburger & back icons of the new Toolbar viewGroup. Beside, I'm using the v7 compatibility library.
我听说,我们不能在运行时改变应用程序的主题,但我正在寻找一个答案,即使它不那么干净的方式。
I heard that we cannot change app theme during runtime, but I'm looking for an answer, even if it's not so clean way.
感谢你了!
编辑:
我想通探微了Gmail是做什么的,我想,当你点击搜索图标,白色汉堡包图标变成灰色的了。
I juste figured that gmail is doing what i want, when you click on the search icon, the white hamburger icon turn into grey back.
等待更多...
推荐答案
我花了一天,打了不同的实现。所以我认为,最好的办法待办事项,它复制粘贴DrawerArrowDrawable从AppCompat V7库。
I spent one day, played with different implementation. So my opinion, the best way todo that it copy paste DrawerArrowDrawable from AppCompat v7 library.
https://gist.github.com/IstiN/5d542355935fd7f0f357 - 采取看看在code有一些优化
https://gist.github.com/IstiN/5d542355935fd7f0f357 - take a look on the code with some optimization
不是你可以用它在你与code主要活动如下
than you can use it in your main activity with code below
DrawerArrowDrawable drawable = new DrawerArrowDrawable(this, this);
ImageView menuButton = (ImageView) findViewById(R.id.arrow);
menuButton.setImageDrawable(drawable);
menuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((DrawerLayout)findViewById(R.id.drawer)).openDrawer(Gravity.START);
}
});
当你开始新的片段,你需要在同一个地方再创建一个视图,并添加第二个code到您的片段
when you start new fragment, you need to create one more view on the same place and add second code to your fragment
private DrawerArrowDrawable mArrowDrawable;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mArrowDrawable = new DrawerArrowDrawable(getActivity(), getActivity());
ImageView topButton = (ImageView) view.findViewById(R.id.arrow);
topButton.setImageDrawable(mArrowDrawable);
topButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
closeSearch();
}
});
//run animation from hamburger to arrow
animate(0, 1, null);
....
private void animate(int startValue, int endvalue, Animator.AnimatorListener listener) {
ValueAnimator anim = ValueAnimator.ofFloat(startValue, endvalue);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float slideOffset = (Float) valueAnimator.getAnimatedValue();
mArrowDrawable.setProgress(slideOffset);
}
});
anim.setInterpolator(new DecelerateInterpolator());
anim.setDuration(300);
if (listener != null) {
anim.addListener(listener);
}
anim.start();
}
,使动画从箭头汉堡包处理后退按钮,然后执行code
to make animation from arrow to hamburger handle back button and execute code
animate(1, 0, null);
您还需要等待您的片段,而动画将无法完成,但它的另一个问题。
you also need to wait in your fragment while animation will not finish, but it another questions.
如果您有任何问题,请在注释中。
If you have any questions ask in comments.
这篇关于机器人 - 改变汉堡/后退图标颜色programaticaly运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!