操作栏操作图标未显示
Actionbar action icons not showing up
我已经搜索了很多问题但无法解决我的问题。请帮助我。我已经使用 app:showAsAction="always"
但即使是它们我也无法在操作栏上获得图标。我也试过 app:showAsAction="ifRoom"
但没有用。我是 android 的初学者,我会非常乐意提供帮助。提前致谢
我的 manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mavilla.laundrynotes" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Apptheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我的style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Apptheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar.Solid.Apptheme</item>
</style>
<style name="ActionBar.Solid.Apptheme" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">@color/Crimson</item>
</style>
</resources>
我的menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item
android:id="@+id/action_settings"
android:title="Add"
android:icon="@mipmap/add"
app:showAsAction="always" />
</menu>
main_activity.java
package mavilla.laundrynotes;
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@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.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
使用以下代码并进行您自己的自定义:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:icon">@android:color/transparent</item>
<item name="android:activatedBackgroundIndicator">@drawable/activated_background</item>
<item name="android:actionBarWidgetTheme">@style/ActionBarWidget</item>
<item name="android:actionBarItemBackground">@color/teal</item>
<item name="android:divider">@color/teal</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">@style/NavDrawerActionBar</item>
<item name="android:actionModeBackground">@color/teal</item>
<item name="android:icon">@drawable/menu</item>
<item name="android:actionModeCloseDrawable">@drawable/back</item>
</style>
<style name="NavDrawerActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/teal</item>
<item name="android:actionModeCloseDrawable">@drawable/back</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/teal</item>
<item name="android:gravity">center</item>
<item name="android:displayOptions">showHome|useLogo</item>
<item name="android:height">@dimen/action_bar_height</item>
</style>
<style name="ActionBarWidget" parent="Theme.AppCompat.Light.DarkActionBar"></style>
</resources>
我已经搜索了很多问题但无法解决我的问题。请帮助我。我已经使用 app:showAsAction="always"
但即使是它们我也无法在操作栏上获得图标。我也试过 app:showAsAction="ifRoom"
但没有用。我是 android 的初学者,我会非常乐意提供帮助。提前致谢
我的 manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mavilla.laundrynotes" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Apptheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我的style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Apptheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar.Solid.Apptheme</item>
</style>
<style name="ActionBar.Solid.Apptheme" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">@color/Crimson</item>
</style>
</resources>
我的menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item
android:id="@+id/action_settings"
android:title="Add"
android:icon="@mipmap/add"
app:showAsAction="always" />
</menu>
main_activity.java
package mavilla.laundrynotes;
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@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.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
使用以下代码并进行您自己的自定义:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:icon">@android:color/transparent</item>
<item name="android:activatedBackgroundIndicator">@drawable/activated_background</item>
<item name="android:actionBarWidgetTheme">@style/ActionBarWidget</item>
<item name="android:actionBarItemBackground">@color/teal</item>
<item name="android:divider">@color/teal</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">@style/NavDrawerActionBar</item>
<item name="android:actionModeBackground">@color/teal</item>
<item name="android:icon">@drawable/menu</item>
<item name="android:actionModeCloseDrawable">@drawable/back</item>
</style>
<style name="NavDrawerActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/teal</item>
<item name="android:actionModeCloseDrawable">@drawable/back</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/teal</item>
<item name="android:gravity">center</item>
<item name="android:displayOptions">showHome|useLogo</item>
<item name="android:height">@dimen/action_bar_height</item>
</style>
<style name="ActionBarWidget" parent="Theme.AppCompat.Light.DarkActionBar"></style>
</resources>