是否有可能使用android.widget.chronometer的动作条里面呢? [英] Is it possible to use android.widget.chronometer inside the actionbar?
问题描述
我想添加一个定时器动作条里面。我已经发现这个解决方案在这里:<一href=\"http://stackoverflow.com/questions/17430477/is-it-possible-to-add-a-timer-to-the-actionbar-on-android\">Is它可以将一个计时器添加到动作条上的Android 它使用兼容性:actionViewClass =android.widget.TextView
然后使用一个计时器上的每个至极更新打勾的字符串值。
I wanted to add a timer inside the actionbar. I already found this solution here: Is it possible to add a timer to the actionbar on android? which uses compatibility:actionViewClass="android.widget.TextView"
and then using a timer wich updates on each tick the string value.
我徘徊,如果有人使用已经尝试过应用:actionViewClass =android.widget.chronometer
I wandered if anyone already tried using app:actionViewClass="android.widget.chronometer"
这会是这样,对于菜单:
It would be something like that for the menu:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_live_clock"
android:title=""
app:showAsAction="always"
app:actionViewClass="android.widget.chronometer"/>
</menu>
然后在相应的活动:
And then in the corresponding activity:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.test_chrono, menu);
MenuItem timerItem = menu.findItem(R.id.action_live_clock);
Chronometer timer = (Chronometer) timerItem.getActionView();
timer.setBase(SystemClock.elapsedRealtime());
timer.start();
return true;
}
但是,当我getActionView后检查该计时器值为NULL。我错过了什么,或者这是不可能的?
But when I check after getActionView the timer value is Null. Did I miss something or is this just not possible?
(如动作条我使用从最新的支持库的应用程序兼容性)
(as ActionBar I am using the appcompat from the latest support library)
推荐答案
您可以八方通自定义视图添加到动作条/工具栏。只是谷歌为。
You can allways add a custom view to the actionbar/toolbar. Just google for that.
这篇关于是否有可能使用android.widget.chronometer的动作条里面呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!