2017-02-02 13 views
-5

私のアプリケーションにはSnackbarがあります。入力を受け入れるためにSnackbarEdittextを追加したいと思います。 SnackbarEdittextを追加するにはどうすればよいですか?アンドロイドのsnackbarにedittextをプログラムで追加するには?

+0

http://stackoverflow.com/questions/42384892/how-to-make-modification-android-snackbar-containing-with-layoutinflater-button([これ]を試してみてください)to button and response –

答えて

0

新しいビューを展開してsnackBarのレイアウトに追加する必要があります。

// Make snackbar 
Snackbar snackbar = Snackbar.make(rootView, "", Snackbar.Snackbar.LENGTH_INDEFINITE); 
// Fetch the layout 
Snackbar.SnackbarLayout sLayout = (Snackbar.SnackbarLayout) snackbar.getView(); 
// remove the default textView 
TextView textView = (TextView) sLayout.findViewById(android.support.design.R.id.snackbar_text); 
textView.setVisibility(View.GONE); 


// Inflate custom view (have an edittext in this) 
View newView = mInflater.inflate(R.layout.edittext_layout, null); 

sLayout.setView(newView,0); 
1
//Custom layouts are discouraged due to the intended use of Snackbars,but this will do your task! 
    LinearLayout linearLayout = (LinearLayout)findViewById(R.id.linear_layout_root); 

    final Snackbar snackbar = Snackbar.make(linearLayout, "Hey Whats Up", Snackbar.LENGTH_INDEFINITE); 
    Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView(); 

    // Inflate your custom view with an Edit Text 
    LayoutInflater objLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View snackView = objLayoutInflater.inflate(R.layout.custom_snac_layout, null); // custom_snac_layout is your custom xml 

    layout.addView(snackView, 0); 
    snackbar.show(); 

enter image description here

+0

@Priyanka Gを使ってSnackbarにeditTextを含めるには、この回答をチェックしてください。 –

+0

はい。できます。それは私の時間を節約します。ありがとうございました。 –

+0

@Priyanka Gそれが動作する場合は、それを受け入れられた答えとしてマークすることができます:) –

関連する問題