4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AndroidのActionBarにメニューが表示されない!

Posted at

"invalidateOptionsMenu" is your friend.

AlloyではActionBarにメニューボタンを設置することができます。

<Alloy>
  <Window title="素敵なアプリ">
    <LeftNavButton platform="ios">
      <Button id="closer" onClick="closeWindow">閉じる</Button>
    </LeftNavButton>
    <RightNavButton platform="ios">
      <Button id="closer" onClick="openEditWindow">編集</Button>
    </RightNavButton>
    <ActionBar id="actionbar" title="素敵なアプリ" platform="android" />
      <Menu platform="android">
        <MenuItem id="scanner" title="閉じる" onClick="closeWindow" />
        <MenuItem id="scanner" title="編集" onClick="openEditWindow" />
      </Menu>
<!--以下略-->

これで問題なく動作するケースがほとんどなのですが、時々、いやもうこれが本当に困っちゃうんですけど、時々ちゃんと動かないことがあります。

そんな時は、深追いせずに

$.index.addEventListener('open', function(e){
  if(OS_ANDROID){
    var activity = $.index.getActivity();
    if(activity){
      activity.invalidateOptionsMenu();
    }
  }
});

「invalidateOptionsMenu」で再描画させることができます。

これを応用すると、動的にメニューを作成・編集することもできます。

How to access Android Actionbar's Menu in Titanium Alloy

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?