2015-05-01 3 views
14

मेरे Toolbar और EditText नज़र जोड़ें:EditText टूलबार में इस तरह

enter image description here

मैं एक ActionView के रूप में जोड़ने की कोशिश की, लेकिन मैं यह परिणाम मिला:

enter image description here

यह मूल रूप से हाल ही में जोड़े TextView

के बिना मेरे शब्द 'टैप नीचे' शीर्षक के रूप में

यहाँ मैं क्या किया है:

menu.xml

<menu> 
    ... 
    ... 
    <item 
     android:id="@+id/edit_text_menu" 
     android:orderInCategory="300" 
     android:title="Tap Below" 
     android:actionLayout="@layout/edit_text_layout" 
     app:showAsAction="ifRoom|collapseActionView" 
     /> 
</menu> 

edit_text_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<EditText xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/myEditText" 
    android:background="#000000"> 

</EditText> 

मैं ऐसा करके सोचा कि मैं Toolbar करने के लिए अपने EditText लेआउट जोड़ने ... कोई कर सकता हूँ कृपया सहायता कीजिए?

वैकल्पिक रूप से, क्या कोई चाल है जहां मैं Toolbar पर ओवरले कर सकता हूं?

मैंने <item name="windowActionModeOverlay">true</item> जोड़ने की कोशिश की लेकिन यह कुछ भी नहीं किया।

+2

बस अपने 'ToolBar' के लिए एक्सएमएल के लिए' EditText' जोड़ें। यह शायद सबसे आसान तरीका है। –

+0

महान काम करता है! लेकिन यह मेरे कोड के माध्यम से इसे मेनू आइटम के रूप में कैसे नहीं जोड़ता है? – user2456977

+0

मेनू "विकल्प मेनू" के लिए है। यह भिन्न है। यहां देखें: http://developer.android.com/guide/topics/ui/menus.html#options-menu। –

उत्तर

26

अपने ToolBar के लिए एक्सएमएल में EditText जोड़ें। यह शायद सबसे आसान तरीका है।

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 
     <EditText 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/myEditText" 
     android:background="#000000" /> 
</android.support.v7.widget.Toolbar> 
+0

अंतिम पंक्ति को –

+2

@OmidAminiva धन्यवाद में ठीक किया जाना चाहिए! अगली बार एक 'संपादन' जमा करें। –

+0

यह क्यों कम किया गया था? यह काम। –

6
  1. टूलबार xml में EditText जोड़ें।

  2. शीर्ष पर अपने Activity's xml लेआउट में Toolbar जोड़ें।

  3. ActionBar के रूप में उपकरण पट्टी सेट करें:

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
        setSupportActionBar(toolbar); 
    } 
    

इस टूलबार ActionBarEditText अंदर के साथ "बन" कर देगा।

+0

हम गतिविधि में संपादन कैसे प्राप्त करेंगे? –

0

उपयोग belove कोड

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

     <TextView 
      android:textColor="@color/colorAccent" 
      android:text="June 14" 
      android:textAllCaps="true" 
      android:layout_gravity="right" 
      android:layout_marginRight="11dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/tv_daily" /> 

    </android.support.v7.widget.Toolbar>