我在溢出菜单中遇到问题。通常,以下MainActivity中的代码将适用于常规主题:
package pokon548.example;
import android.app.*;
import android.os.*;
import android.view.*;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// TODO: Implement this method
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// TODO: Implement this method
switch (item.getItemId()) {
case R.id.item:
break;
}
return true;
}
}
这是menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/item"
android:title="Item"/>
</menu>
styles.xml:
<resources>
<style name="AppTheme" parent="@android:style/Theme.Material.Light.Dialog">
<item name="android:colorPrimary">#FFEC5F67</item>
<item name="android:colorPrimaryDark">#FFEC5F67</item>
<item name="android:colorAccent">#FFEC5F67</item>
<item name="android:textColorSecondary">#FFEC5F67</item>
</style>
</resources>
布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
>
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
但是,如果我将主题从Theme.Material.Light更改为Theme.Material.Light.Dialog,则溢出菜单按钮(ActionBar中的三个点)将不会显示在“活动”中。
在这种情况下,有什么方法可以显示“溢出”菜单?