2014-11-04 53 views
1

我是android新手,而自定义动作栏我注意到,首先它首先显示旧的(默认)动作栏,然后显示自定义动作栏。另外我想为操作栏标题设置文本颜色。 我的代码段是在android中自定义动作栏首先显示默认动作栏

public class MainActivity extends ActionBarActivity { 
    MenuItem searchItem; 
    SearchView searchView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     ActionBar ab = getSupportActionBar(); 

     ab.setTitle("Modification"); ab.setIcon(R.drawable.ap); 
     ab.setBackgroundDrawable(new 
     ColorDrawable(Color.parseColor("#00AA00"))); 
     ab.setSubtitle("Modification"); 

     setContentView(R.layout.activity_main); 

我认为必须有一些愚蠢的错误。
请帮忙。

回答

1

试试这个..
创建theme.xml作为如下

<resources> 
<!-- the theme applied to the application or activity --> 
<style name="CustomActivityTheme" parent="@android:style/Theme.Holo"> 
    <item name="android:actionBarStyle">@style/MyActionBar</item> 
    <!-- other activity and action bar styles here --> 
</style> 
<!-- style for the action bar backgrounds --> 
<style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar"> 
    <item name="android:background">#5477B1</item> 
</style> 

然后在你的AndroidManifest.xml 提到这应用标签

<application 
    .. 
    android:theme="@style/CustomActionBarTheme" 

好运

+1

谢谢。有用。 – 2014-11-04 12:07:34

+0

@Ichigo Kurosaki 大家好我有同样的问题在这里看到你可以请点击这里查看 http://stackoverflow.com/q/26716029/3255471 – Biftor 2014-11-04 17:24:26

0

尝试这样,

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     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); 
    } 

或 的操作栏创建样式和使用自定义背景:

<resources> 
    <!-- the theme applied to the application or activity --> 
    <style name="CustomActivityTheme" parent="@android:style/Theme.Holo"> 
     <item name="android:actionBarStyle">@style/MyActionBar</item> 
     <!-- other activity and action bar styles here --> 
    </style> 
    <!-- style for the action bar backgrounds --> 
    <style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar"> 
     <item name="android:background">@drawable/background</item> 
     <item name="android:backgroundStacked">@drawable/background</item> 
     <item name="android:backgroundSplit">@drawable/split_background</item> 
    </style> 
</resources> 
+0

您好,我们已经尝试你的方法,但这并没有解决我的问题。请向我们提供一些其他方法来解决此问题。 – 2014-11-04 11:44:54

+0

@Moradiya Akash 大家好我有同样的问题在这里看到你可以请检查在这里 http://stackoverflow.com/q/26716029/3255471 – Biftor 2014-11-04 17:24:48