2015-05-29 3 views
1

Я хочу сделать панель действий красной, и она не работает. Он запускает приложение, а затем сразу же говорит: «К сожалению, панель действий остановлена», и я вижу приложение действительно быстрым и оно читается. Я искал часы, и в Интернете ничего не появилось. Может ли кто-нибудь помочь, потому что я новичок в кодировании?Styling Action Bar (цвет фона) Android

LogCat

 05-29 01:04:39.051 
21993-21993funnestgames.actionbarActivityThread:PauseGC 
java.lang.reflect.InvocationTargetException 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at android.app.ActivityThread.pauseGC(ActivityThread.java:5525) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471) 
     at android.app.ActivityThread.access$900(ActivityThread.java:175) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:146) 
     at android.app.ActivityThread.main(ActivityThread.java:5602) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
     at dalvik.system.NativeStart.main(Native Method) 
     Caused by: java.lang.UnsatisfiedLinkError: Native method not  
     found:dalvik.system.VMRuntime.pauseGc:(Ljava/lang/String;)I 
     at dalvik.system.VMRuntime.pauseGc(Native Method) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
      at android.app.ActivityThread.pauseGC(ActivityThread.java:5525) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471) 
        at android.app.ActivityThread.access$900(ActivityThread.java:175) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:146) 
        at android.app.ActivityThread.main(ActivityThread.java:5602) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
        at dalvik.system.NativeStart.main(Native Method) 

styl.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<!-- the theme applied to the application or activity --> 
<style name="CustomActionBarTheme" 
    parent="@android:style/Theme.Holo.Light.DarkActionBar"> 
    <item name="android:actionBarStyle">@style/MyActionBar</item> 
</style> 

<!-- ActionBar styles --> 
<style name="MyActionBar" 
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse"> 
    <item name="android:background">#F00</item> 
</style> 
</resources> 

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="funnestgames.actionbar" > 

<application 
    android:theme="@style/CustomActionBarTheme" 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name"> 
    <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> 
+0

Я исправил проблему макета журнала для вас. Надеюсь, для кого-то будет достаточно информации. –

ответ

0

Используйте этот код ниже

ActionBar action_bar = getActionBar(); 
action_bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FF0000"))); 

Изменить стиль от

<!-- 
    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="Theme.AppCompat.Light"> 
    <!-- 
     Theme customizations available in newer API levels can go in 
     res/values-vXX/styles.xml, while customizations related to 
     backward-compatibility can go here. 
    --> 
</style> 

<!-- Application theme. --> 
<style name="CustomActionBarTheme" parent="AppBaseTheme"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
</style> 

+0

Я пробовал, чтобы он не работал. плохо повторите попытку. в правом классе java? в "onCreateOptionsMenu"? – stacker1

+0

попробуйте это .. я только что отредактировал –

+0

Хорошо. Это работает. (YAY) Сделано все белым. теперь как сделать панель действий красной? Как я уже сказал, я новичок в кодировании. – stacker1

0

Попробуйте

<style name="ActionBar.Solid.Example" parent="@android:style/Widget.Holo.Light.ActionBar.Solid"> 
     <item name="android:background">Your color you want or drawable</item> 
     <item name="android:backgroundStacked">Your color you want or drawable</item> 
     <item name="android:backgroundSplit">Your color you want or drawable</item> 
</style> 

И добавить это на AppTheme приложение:

<item name="android:actionBarStyle">@style/ActionBar.Solid.Example</item> 

Или попробовать использовать tools

+0

Я пробовал, и ничего не случилось, он остался белым. – stacker1

+0

Вы пытаетесь использовать эти инструменты? и скопируйте весь стиль в ваши styles.xml. помните, скопировать все на res ... –

+0

да Я пробовал инструменты, и он не работал – stacker1