5

मैंने अपने एक्शनबार में SearchView विजेट को एक कस्टम थीम फिट करने के लिए इस question के लिए महान उत्तर का पालन किया है। यह पोर्ट्रेट मोड के लिए बस ठीक काम करता है, लेकिन परिदृश्य में ओएस कंटेंट स्क्रीन एस्टेट को अधिकतम करने के लिए एक्शनबार की ऊंचाई को कम कर देगा। सिर्फ अन्य मदों की तरह ActionBar में हाशिए के बिना SearchView विजेट फिटिंग के बजाय, यह शीर्ष पर काटा जाता है:परिदृश्य में कट ऑफ कस्टम खोज दृश्य पृष्ठभूमि को कैसे ठीक करें?

SearchView widget with chopped off top

मैं Android स्रोत की रेस-फ़ोल्डर के माध्यम से खोदा है, लेकिन कर सकते थे कोई विशेष लेआउट या संसाधन नहीं ढूंढें जो यह सुनिश्चित करेगा कि यह कैसे ठीक किया जाए या यहां तक ​​कि कैसे एंड्रॉइड स्वयं डिफ़ॉल्ट होलो SearchView विजेट को कम एक्शनबार में फ़िट करने का प्रबंधन करता है।

किसी भी अंतर्दृष्टि की सराहना की जाती है। धन्यवाद।

उत्तर

3

आपको संपादन टेक्स्ट के एक छोटे संस्करण का उपयोग करना होगा। ड्रॉबल्स इंस्टेंटिक आयाम डिफ़ॉल्ट संपादन टेक्स्ट ड्रॉबल्स से छोटे होते हैं।

चेक बाहर ड्रॉएबल यहां इस्तेमाल किया

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/frameworks/support/v7/appcompat/res/drawable/abc_textfield_searchview_holo_dark.xml?av=f

+0

आखिर में इस समस्या को हमारे बैक लॉग से ठीक करने के लिए मिल गया। संकेत के लिए बहुत बहुत धन्यवाद! – Chris

3

मैं एक ऐसी ही समस्या थी, और बस EditText के गुरुत्वाकर्षण बदलकर इसे ठीक करने में सक्षम था:

try { 
    int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); 
    AutoCompleteTextView searchPlate = (AutoCompleteTextView) searchView.findViewById(searchPlateId); 

    //fixes the gravity (fixes text cutoff for landscape mode) 
    searchPlate.setGravity(Gravity.LEFT|Gravity.BOTTOM); 
} 
catch (Throwable t) 
{ 
    //not sure if the above code will always work (layouts change), but works well for the current API. 
    t.printStackTrace(); 
} 
+0

यह भी एक संभावित काम की तरह लगता है, हालांकि जोनाथन का जवाब जाने का तरीका है यदि आप संसाधनों को मैन्युअल रूप से पुनर्स्थापित करने के लिए समय बर्दाश्त कर सकते हैं। – Chris

0

SearchView है आसानी से अनुकूलित नहीं किया गया लेकिन मुझे एक काम मिल गया। मेरा शोध और कोड ज्यादातर यहां मिले पहले उत्तर से लिया गया है: Changing the background drawable of the searchview widget। इस तरह मेरी एक्सएमएल फ़ाइल में पृष्ठभूमि सेट करने के बाद:

 `<SearchView 
     android:layout_width="match_parent" 
     android:layout_height="30dp" 
     android:background="@drawable/rounded_grey_search_bar" 
     android:clickable="true" 
     android:iconifiedByDefault="false"/>` 

मैं अपने जावा फ़ाइल में निम्नलिखित कोड जोड़ा SearchView की गद्दी को बदलने के लिए:

SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); 


    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); 

    int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null); 
    searchView.findViewById(searchPlateId).setBackgroundResource(R.drawable.rounded_grey_search_bar); 

    int voiceSearchPlateId = searchView.getContext().getResources().getIdentifier("android:id/submit_area", null, null); 
    searchView.findViewById(voiceSearchPlateId).setBackgroundResource(R.drawable.rounded_grey_search_bar); 

    int searchTextViewId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); 
    TextView searchTextView = (TextView) searchView.findViewById(searchTextViewId); 
    searchTextView.setPadding(20, 20, 20, 20); 

गद्दी की स्थापना मुझे पाने के लिए अनुमति दी पाठ जहां मैं चाहता था।

संबंधित मुद्दे