操作栏未显示在自定义标题中

时间:2013-11-24 21:56:21

标签: android android-actionbar android-theme

我已经设置了自定义标题布局,但无法看到操作栏的三个条形图。我在没有硬件菜单按钮的三星Note 10.1上使用这个应用程序。我的父母是android:theme所以我不确定为什么操作栏被隐藏。目标版本“16 minversion is”14“

以下是使用自定义主题的清单文件设置。

       <application
    android:allowBackup="true"
    android:icon="@drawable/logo_icon" 
    android:label="@string/app_name"
    android:theme="@style/CustomTheme">

这是添加项目的custom_title.xml。

   <resources>
<style name="CustomWindowTitleBackground">
    <item name="android:background">#323331</item>
</style>

<style name="CustomTheme" parent="android:Theme">

    <item name="android:windowTitleSize">45dip</item>
    <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>

这是构成自定义标题的title.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<ImageView
    android:id="@+id/image_icon"
    android:layout_width="30dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:layout_marginLeft="7dp"
    android:src="@drawable/logo_icon" />

<TextView
    android:id="@+id/Application"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:text="   ColorMaker Simple RGB   "
    android:textSize="20dp" />

<!-- Bluetooth info -->

<TextView
    android:id="@+id/textbluetooth"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:text="BlueTooth: "
    android:textSize="20dp" />

<ImageView
    android:id="@+id/image_bt_on_off"
    android:layout_width="15dp"
    android:layout_height="15dp"
    android:layout_gravity="center_vertical"
    android:background="@drawable/circle" />

<!-- Network  info -->

<TextView
    android:id="@+id/textspacer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:text=" | "
    android:textSize="20dp" />

<TextView
    android:id="@+id/textnetwork"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:text="Network : "
    android:textSize="20dp" />

<TextView
    android:id="@+id/textspacer1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:text=" | "
    android:textSize="20dp" />

<!-- Fade  info -->

<TextView
    android:id="@+id/textfade_on_off"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:text="Fade : "
    android:textSize="20dp" />

<TextView
    android:id="@+id/textspacer2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:text=" | "
    android:textSize="20dp" />

菜单项

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.title:
        startActivity(new Intent(this, Prefrences.class));
        // Activity2.this.startActivity(myIntent);

        break;

    }

    return true;
}

记录错误

11-24 17:47:54.593: D/AndroidRuntime(6607): Shutting down VM
11-24 17:47:54.593: W/dalvikvm(6607): threadid=1: thread exiting with uncaught exception (group=0x40d0f2a0)
11-24 17:47:54.601: E/AndroidRuntime(6607): FATAL EXCEPTION: main
11-24 17:47:54.601: E/AndroidRuntime(6607): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.simplergb/com.example.simplergb.SimpleRGB_Main}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
11-24 17:47:54.601: E/AndroidRuntime(6607):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2129)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2154)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at android.app.ActivityThread.access$700(ActivityThread.java:146)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1260)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at android.os.Looper.loop(Looper.java:137)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at android.app.ActivityThread.main(ActivityThread.java:4949)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at java.lang.reflect.Method.invokeNative(Native Method)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at java.lang.reflect.Method.invoke(Method.java:511)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at dalvik.system.NativeStart.main(Native Method)
11-24 17:47:54.601: E/AndroidRuntime(6607): Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
11-24 17:47:54.601: E/AndroidRuntime(6607):     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:289)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3118)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3358)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:314)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at android.app.Activity.setContentView(Activity.java:1920)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at com.example.simplergb.SimpleRGB_Main.onCreate(SimpleRGB_Main.java:169)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at android.app.Activity.performCreate(Activity.java:5185)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
11-24 17:47:54.601: E/AndroidRuntime(6607):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093)
11-24 17:47:54.601: E/AndroidRuntime(6607):     ... 11 more

1 个答案:

答案 0 :(得分:0)

不确定这是否是罪魁祸首,但在

<style name="CustomTheme" parent="android:Theme">

尝试将android:Theme替换为 android:Theme.Holo (或android:Theme.Holo.Light或其他一些后代,如果您愿意的话)。

As the docs state

  

操作栏包含在使用Theme.Holo的所有活动中   主题(或其后代之一)

在我当前的应用程序中,首先需要让Action Bar显示出来。


嗯,当你提到“3点动作栏”时,你真的是指行动栏 溢出 吗?请参阅文档中的 Adding Action Items 。您的菜单资源文件是什么样的?