2017-06-15 20 views
-2

我已更新我的问题以使其更容易理解并提供更多信息。如何编辑操作栏上的文本和后退箭头颜色

下面的图像是我当前的GUI,它是第二个活动,我试图将文本颜色和箭头图标颜色编辑为黑色。

在GUI中的动作条通过编辑AndroidManifest.xml中使用的Java方法,onNavigationItemSelected(菜单项项目),这将带来我回到父活动,当我点击箭头图标

内部产生AndroidManifest.xml我已经定义了标题“Trip”及其父活动名称。

那么有没有办法改变文字和图标的颜色?

当前GUI

enter image description here

XML用于GUI

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.android.iplanner.Trip.ActivityTrip"> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fabAddTrip" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     app:backgroundTint="@color/colorPrimary" 
     android:clickable="true" 
     app:srcCompat="@drawable/ic_add_black_24px" /> 

</RelativeLayout> 

styles.xml

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 

    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

</resources> 

的AndroidManifest.xml

<activity 
      android:name=".Trip.ActivityTrip" 
      android:label="Trip" 
      android:parentActivityName=".ActivityMain" /> 
+0

显示您的工具栏xml。 –

回答

1

这是我用来设置工具栏

private void setupToolbar() { 
     MyLogger.getInstance().writeInfo(TAG, "setupToolbar"); 
     toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     toolbar.setNavigationIcon(R.drawable.ic_arrow_back_24dp);//Image Icon 
     toolbar.setNavigationOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       MyLogger.getInstance().writeInfo(TAG, "Toolbar Clicked"); 
        onBackPressed(); 
      } 
     }); 
    } 
0
<style name="MyApp.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">  
<!-- THIS is where you can color the arrow! --> 
<item name="colorControlNormal">@color/my_awesome_color</item> 

在样式添加MyApp.ActionBarTheme功能

<style name="MyTheme" parent="Theme.AppCompat.Light">   
<item name="actionBarTheme">@style/MyApp.ActionBarTheme</item> 
<item name="actionBarStyle">@style/MyApp.ActionBar</item> 

<style name="MyApp.ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar"> 
<item name="elevation">0dp</item>  
<!-- style for actionBar title --> 
<item name="titleTextStyle">@style/ActionBarTitleText</item> 
<!-- style for actionBar subtitle --> 
<item name="subtitleTextStyle">@style/ActionBarSubtitleText</item> 

<!-- 
the actionBarTheme doesn't use the colorControlNormal attribute 
<item name="colorControlNormal">@color/my_awesome_color</item> 
--> 

0

尝试这种改变标题:

yourToolbar.setTitle("My title”); 

,这改变图标:

final Drawable yourIcon = getResources().getDrawable(R.drawable.your_icon); 
yourIcon.setColorFilter(Color.parseColor(color_you_want), 
PorterDuff.Mode.SRC_ATOP); 
getSupportActionBar().setHomeAsUpIndicator(yourIcon); 
0

感谢您的帮助和抱歉浪费大家的时间。

我已经设法将文本颜色和图标颜色更改为黑色。

我的解决办法是下面:

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 

    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

</resources> 

通过改变AppTheme为 “Theme.AppCompat.Light” 和AppTheme.AppBarOverlay为 “ThemeOverlay.AppCompat.Light”。

相关问题