使用删除按钮创建自定义edittext

时间:2015-08-18 19:22:24

标签: android android-edittext textview

我想创建一个自定义的EditText,看起来像这样。

我不知道怎么回事。任何帮助都会很棒!

1 个答案:

答案 0 :(得分:0)

您需要制作custom view group。制作XML文件,最好是通过查看您的设计,使用relative layout的根。将buttons的部分放在顶部,然后在底部添加edittext。 然后使用您的Java Custom View Group Class,您可以将所有内容连接起来(代码)作为单个小部件。然后,只需在其他xml布局中包含自定义视图组。

我在下面提供了两个教程。现在,这是一个非常酷的技巧。制作自定义XML layout,但不要将内容包装在类路径标记中,例如<com.vogella.android.view.compoundview.CustomViewGroupCustom View Group Class的java代码中对自定义xml视图进行膨胀。基本上在Custom View Group Class中,您将添加以下代码。查看我的Github Porject以获取完整示例。

private void inflateCustomView() {
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.counter_layout, this, true);
}

这是帮助您了解制作自定义视图组的两个教程。 Custom View Groups from The Geek Stuff Vogella Custom View Groups

相关问题