2015-03-16 7 views
0

Я новичок в разработке android. Мне нужно настроить тему приложения. Так что для меня я создал свой собственный стиль. В моей теме я хочу, чтобы цвет панели действий был другим. Я пытался это сделать но я моя панель действий не видна. Пожалуйста, помогите мне. КодActionBar не отображается

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
    </style> 


    <style name="HsJobTheme" parent="android:Theme.Holo.Light"> 
     <item name="android:actionBarStyle">@style/MyActionBar</item> 


    </style> 

    <style name="MyActionBar" parent="android:Theme.Holo.Light.DarkActionBar"> 
     <item name="android:background">#ffcdc434</item> 
    </style> 

</resources> 
+0

Используйте 'AppCompat' не' Holo'. В вашей основной «Активности» необходимо расширить «ActionBarActivity». –

ответ

0

В коде:

ActionBar actionBar=getActionBar(); 

Затем используйте:

actionBar.setBackgroundDrawable(R.style.MyActionBar); 
+0

Но я настраиваю тему в манифесте, пока не получаю ее – Anuj

+0

Надеюсь, что вы используете ActionBar! – asdec90

+0

Я использую normal Activity – Anuj

0

Создание макета как custom_actionbar.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="50dp" 
android:background="@drawable/black_pattern" > 

<TextView 
    android:id="@+id/title_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:textAllCaps="true" 
    android:margin="5dp" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textColor="#fff" 
    android:textStyle="bold" /> 

</RelativeLayout> 

В вашей деятельности в onCreate(), сделать так ..

ActionBar mActionBar = getActionBar(); 
    mActionBar.setDisplayShowHomeEnabled(false); 
    mActionBar.setDisplayShowTitleEnabled(false); 
    LayoutInflater mInflater = LayoutInflater.from(this); 

    View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null); 
    TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text); 
    mTitleTextView.setText("My Own Title"); 
    mActionBar.setCustomView(mCustomView); 
    mActionBar.setDisplayShowCustomEnabled(true); 
+0

проверить этот учебник http://tech-papers.org/android-working-with-action-bar/ –

0

свою работу для меня

<android.support.design.widget.AppBarLayout android:layout_height="wrap_content" 
    android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar android:id="@+id/toolbar" 
     android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> 

</android.support.design.widget.AppBarLayout> 

<include layout="@layout/content_main1" /> 

1-набор цвет-> Android: фон = "# код цвет " не забудьте Публичный класс Деятельность расширяет AppCompatActivity { } 2-сторонняя андроид-студия или используйте этот код

ActionBar bar = getActionBar(); 
bar.setBackgroundDrawable(new ColorDrawable("COLOR")); 
Смежные вопросы