飞雪团队

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 7940|回复: 0

Android:对所有菜单项使用 app:showAsAction=\\”always\\”

[复制链接]

6483

主题

6571

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
21773
发表于 2022-2-12 18:11:02 | 显示全部楼层 |阅读模式
                        ' @5 E' _' [0 q3 {
                                                        <h2>Android: using app:showAsAction="always" for all menu items</h2>8 ~0 t$ A$ N& u2 X# X
<div id="fc">3 P. H$ f4 P0 N& T* s
<p></p><center> <script src="/c1.js"></script></center><p></p>& a' Y4 |/ Q9 n. Q) h) c
<p>在我正在开发的这个应用程序的主要活动中,我希望 4 个菜单项始终显示在操作栏中。我对菜单的每个项目都使用了 showAsAction = "always",因为我的此活动中的主题删除了标题并仅显示图标,因此我知道操作栏中将有很大的空间用于显示图标。但是,我不确定是否将所有项目都设置为"始终"" 是正确的做法.. 还有其他方法还是我正确?</p>
7 z7 U6 U( V/ B- _$ j<p>ps: showAsAction = "ifRoom" 只允许我的应用在操作栏中显示 2 个项目..</p>
+ ?4 i4 a; G  K2 @4 O* g2 s<div class="suo-content"><div style="text-align: right;">* q$ W7 b4 r* U% q8 H! E* G
                <div class="xControl"><i class="fa fa-caret-right"></i>
5 l; N0 h' U0 [! R                        <span class="xTitle"></span>   U( z% f4 k8 r* t
                        相关讨论
& M  A/ w' W* [  b) B) u                        <div style="clear: both;"></div>
3 W$ F  T* g' a# X, M                </div>: x1 h8 E' @& i- h9 l
                <div class="xContent" style="display: none;"><p></p>
+ x5 s7 J, ^; y4 e1 Y: J<ul>
6 `0 ~- a9 c9 C6 d2 [<li>如果您有兴趣创建您选择的 ActionBar,请在此处参考我的回答 stackoverflow.com/questions/26439715/...</li>
9 l$ E& k0 ]( \7 o</ul>
+ e7 }/ E$ [7 Z+ E- F<p></p></div>
: ?1 _9 _+ T8 a4 o% }  L2 f& X        </div><p></p></div>2 \9 i" {8 d. [
<hr>
) t- e9 H, N+ F, Q- r0 ~" ~<p>如果您想确保拥有所有 4 个图标,最好创建自己的 ActionBar 并做任何您喜欢的事情。</p>6 v9 w, Q( I' i( |4 |# Z5 E
<p>在原来的 ActionBar 中你可以使用 :</p>) q. C' y. ^* N& P9 i
<blockquote>  L5 A3 I; K! t- C( S  y
<p>android:showAsAction="always"</p>
" k; u+ W* C8 \  S( X+ v</blockquote>
, j5 w7 H% i9 K! }<p>这将迫使他们在那里,但如果仍然没有足够的空间,请考虑发生了什么。</p>
2 s  i: `. H$ |" C<blockquote>; [# x) ~0 Y& \5 b
<p></p><center> <script src="/c2.js"></script></center><p></p>
+ e; A' p& X& O( U<p>When contained within the action bar there is a finite maximum of action items based on the device's density-independent width. The action items can also not cover more than half the width of the action bar.</p># S0 p8 n1 e- _6 _. M
</blockquote>8 X1 a) v  y1 s! N9 {
<p>从这里</p>
' d: c" I/ ]2 d& D$ N<hr>$ V5 f1 k& r! a+ ?; R/ b
<p>你可以通过编程来完成这个任务:</p>- L$ f; U* d& b5 S$ v' ]
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;width:100%;"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br>11<br>12<br></div></td><td><div class="text codecolorer">@Override<br>. }: W* b) ~# D+ u1 i, l$ V7 R2 u
public boolean onCreateOptionsMenu(final Menu menu) {<br>: q1 p8 V; x7 j( R
&nbsp; &nbsp; super.onCreateOptionsMenu(menu);<br>* P; J# c- T, R9 {
<br>" |* l% H! f* I# {
&nbsp; &nbsp; getMenuInflater().inflate(R.menu.main, menu);<br>
, n# |! b6 w  [8 ]4 u$ l7 a<br>
! X, ]& L$ l2 r, v&nbsp; &nbsp; for (int i = 0; i &lt; menu.size(); i++) {<br>
' o9 W9 y  x6 s- P: m&nbsp; &nbsp; &nbsp; &nbsp; menu.getItem(i).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);<br>% t7 S' ]- f3 n$ M2 e- a8 ?2 p' s
&nbsp; &nbsp; }<br>$ Q/ ~# {1 t" g1 P8 i
<br>' |. G9 Y5 V" r  H, R, G7 E* X5 H
&nbsp; &nbsp; return true;<br>
* d+ k  J! l( N% A& }+ I8 T; w- ~}</div></td></tr></tbody></table></div>' H+ X5 D4 B8 A& q& `/ n- Z
<hr></div>1 F, M# L2 p( g, x5 C7 n+ p
                                                                                                                                                                                               
. W/ L5 y! ^) V7 N) d                                               
回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|飞雪团队

GMT+8, 2025-5-1 16:12 , Processed in 0.060989 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表