2014-12-29 31 views
0

我正在嘗試使文本成爲搜索視圖的用戶類型爲白色。 「android:searchViewTextField」給出錯誤。我不能爲一個全球性的風格找到合適的名字:Android SearchView文本顏色

<style name="AppTheme" parent="@style/_AppTheme"/> 

<style name="_AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
    <item name="android:searchViewTextField">@color/white_color</item> 
</style> 

是否有一個全球性的風格,這將隻影響的搜索查看的文本,而不是所有文本框?

回答

1

定義主題 「SearchTextViewTheme」

<style name="SearchTextViewTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
    <item name="android:textColor">@color/white_color</item> 
</style> 

然後

<TextView 
    style="@style/SearchTextViewTheme" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 

其實應用主題必須在佈局XML中明確定義的TextView裏面。因此,你不必擔心主題影響其他文本框

0

這裏是它是如何做插件Xamarin(我基於從帕特里克答案的想法):

 [assembly: ExportRenderer(typeof (CustomSearchBar), typeof (CustomSearchBarRenderer))] 

     namespace Bahai.Android.Renderers 
     { 
     public class CustomSearchBarRenderer : SearchBarRenderer 
    { 
     protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e) 
    { 
     base.OnElementChanged(e); 
     if (e.OldElement == null) 
     { 
      SearchBar element = (SearchBar) this.Element; 
      var native = (global::Android.Widget.SearchView) Control; 

      // do whatever you want to the controls here! 
      //-------------------------------------------- 
      // element.BackgroundColor = Color.Transparent; 
      // native.SetBackgroundColor(element.BackgroundColor.ToAndroid()); 
      // native.SetBackgroundColor(Color.White.ToAndroid()); 

      //The text color of the SearchBar/SearchView 
      AutoCompleteTextView textField = (AutoCompleteTextView) 
       (((Control.GetChildAt(0) as ViewGroup) 
        .GetChildAt(2) as ViewGroup) 
        .GetChildAt(1) as ViewGroup) 
        .GetChildAt(0); 

      if (textField != null) 
       textField.SetTextColor(Color.White.ToAndroid()); 
     } 
    } 
    } 
    } 
1

如果您targed SDK是20或更少,Goolge用於設置SearchView風格的屬性是隱藏的,如果您嘗試在主題中覆蓋它們,則最終會出現編譯錯誤。

您可以使用AppCompat v20 SearchView而不是此tutorial之後的本地SearchView。 AppCompat公開像searchViewTextFieldsearchViewAutoCompleteTextView這樣的屬性來更改AutoCompleteTextView的樣式。

0

這並獲得成功

<style name="myTheme" parent="@style/Theme.AppCompat.Light">  
    <item name="android:editTextColor">#fffff</item> 
    </style> 

上述方案可能在java中工作,但他們不xamarin工作,我想這解決方案將在java中工作。