android笔记之autoCompleteTextView

本文介绍了一个关于Android应用开发中AutoCompleteTextView组件不显示自动补全提示的问题及解决办法。通过调整AndroidManifest.xml文件中的主题设置,成功解决了自动补全提示未显示的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package com.example.autocomplete;



import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		AutoCompleteTextView auto=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
		String[] arr={"a","abc","ab","acd"};
		ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, arr);
		auto.setAdapter(adapter);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}

Activity文件的代码如上所示。

布局文件如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" 
    >

     <AutoCompleteTextView 
        android:id="@+id/autoCompleteTextView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:completionHint="请选择你喜欢的歌曲"
        android:completionThreshold="1"
        android:dropDownHorizontalOffset="20dp"
              
        />

</RelativeLayout>
使用API10开发运行的时候,下方会出现提示的记录有四条,而且点击空白处的时候,会有相应的文字提示出现在文本框中,可是下面的自动补全提示中,竟然没有文字出现,实在是费解。

解决办法:

把  AndroidMainFest.xml中的android:theme="...."     删掉 即可



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

le4

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值