Android控件之相关控件

1、AutoCompleteTextView:自动匹配文本内容

功能:在搜索引擎里面查找内容的时候,我们想要输入的信息就会出现其他与其相关的提示信息

这里写图片描述

我们从上面看到一个很重要的属性 android:completionThreshold=”2” 代表设置多少字符时提示内容。

然后是java代码

这里写图片描述

下面运行之后:

这里写图片描述


2、MutiAutoCompleteTextView :支持多次自动匹配文本内容

当我们同时给多个人发邮件的时候,每次输入一个收件箱都会有提示内容,这就是.MutiAutoCompleteTextView功能。它有个方法setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer())指设置以逗号分隔符为结束的符号

//.xml布局文件里设置一个MultiAutoCompleteTextView控件的代码
 <MultiAutoCompleteTextView
        android:hint="请输入要发送的对象"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/multiAutoCompleteTextView" />

//在MainActivity里实现的代码
public class MainActivity extends AppCompatActivity {

    private ArrayAdapter<String> arrayAdapter;
    private MultiAutoCompleteTextView  multiAutoCompleteTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.auto);
        String data[] = {"[email protected]", "[email protected]", 
        "[email protected]", "[email protected]"};
        arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, data);
        multiAutoCompleteTextView = 
        (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView);
        multiAutoCompleteTextView.setAdapter(arrayAdapter);
        multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    }

这里写图片描述


给Button设置一种效果,把底色改为橘色,点击以后闪现红色的按钮。

利用drawable实现自定义图像

step one :在drawable文件下新建xml文件,shape标签

由于本例子需要两个背景颜色,而shape就是用于自定义形状的,具体的过程:

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

step two 在drawable文件下新建xml文件,selector标签

光有两个图形还不够,我们需要selector将两者联系在一起

这里写图片描述

这里写图片描述

step three 设置Button的background属性
这里写图片描述

这里写图片描述

总的来说,android自定义控件样式在drawable文件夹下的XML文件中,然后通过设置控件的background属性达到效果。

猜你喜欢

转载自blog.csdn.net/zhangyDD/article/details/82498468