本文介绍了如何以编程方式在Android的快餐栏中添加edittext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的申请中有Snackbar.我想在Snackbar中添加Edittext以接受一些输入.如何在Snackbar中添加Edittext?

I have Snackbar in my application. I want to add Edittext in Snackbar to accept some input. How can I add an Edittext in Snackbar?

推荐答案

    //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();

这篇关于如何以编程方式在Android的快餐栏中添加edittext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 20:57