1
1

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.

NavigationViewのmenuItemの要素を取得する

1
Posted at

ナビゲーションドロワーの書くメニュー要素のViewを取得したいとするのだがこれが難しい。

ナビゲーションドロワーに通常使われるNavigationViewだが、特に各要素のViewにアクセスするメソッドは用意されていないようだ。MenuItemなら取れるけど。

customViewを設定しているわけでもないのでfindViewByIdもだめ。

と思っていたらfindViewsWithTextが使えるらしい。

val outViews = ArrayList<View>() |
navigationView.findViewsWithText(outViews, "メニュー1", View.FIND_VIEWS_WITH_TEXT)

空の配列を渡しておけばそのテキストを持つViewを配列に入れておいてくれる。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?