gpt4 book ai didi

android - 设置即将与操作栏支持库一起溢出

转载 作者:行者123 更新时间:2023-11-29 17:54:20 25 4
gpt4 key购买 nike

我正在使用支持库 v3 appcompat 开发一个操作栏。设置选项不会溢出。相反,我需要从我的手机上按菜单,然后设置就会出现....

代码如下:main_activity_actions.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:myapp="http://schemas.android.com/apk/res-auto">
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="ifRoom"
myapp:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:showAsAction="never" />
</menu>

配置:

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />

主 Activity .java

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
Toast.makeText(this, "Search Clicked", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_settings:
Toast.makeText(this, "Settings Clicked", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

}

知道为什么会这样吗?

最佳答案

Actionbar 溢出按钮不会在具有硬件菜单按钮的设备上显示,因为这是设计阻止的,

来自设计文档中的兼容性 here

Android phones with traditional navigation hardware keys don't display the virtual navigation bar at the bottom of the screen. Instead, the action overflow is available from the menu hardware key.

您可以尝试破解以强制显示溢出菜单,请参阅此 answer

关于android - 设置即将与操作栏支持库一起溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20585022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com