Android中如何让一个EditView被点击后出现搜索框,搜索框已经实现
发布网友
发布时间:2022-05-24 06:14
我来回答
共3个回答
热心网友
时间:2023-10-03 03:22
Android有自带的一个控件AutoCompleteTextView
具体用法如下:
main.xml代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="请选择你喜欢的歌曲"
android:completionThreshold="1"
android:dropDownHorizontalOffset="20dp"
android:ems="10"
android:text="AutoCompleteTextView" >
<requestFocus />
</AutoCompleteTextView>
</LinearLayout>
java代码为:
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ImageView;
public class AndroidDemo5Activity extends Activity {
// 定义字符串数组作为提示的文本
String[] books = new String[] { "rollen", "rollenholt", "rollenren", "roll" };
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 创建一个ArrayAdapter封装数组
ArrayAdapter<String> av = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, books);
AutoCompleteTextView auto = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
auto.setAdapter(av);
}
}
热心网友
时间:2023-10-03 03:23
EditView添加onClickListener,在对应的onClick方法里面处理显示逻辑就行了吧
热心网友
时间:2023-10-03 03:23
设置成可点击的,设置监听,然后把你要做的事写进去
热心网友
时间:2023-10-03 03:22
Android有自带的一个控件AutoCompleteTextView
具体用法如下:
main.xml代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="请选择你喜欢的歌曲"
android:completionThreshold="1"
android:dropDownHorizontalOffset="20dp"
android:ems="10"
android:text="AutoCompleteTextView" >
<requestFocus />
</AutoCompleteTextView>
</LinearLayout>
java代码为:
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ImageView;
public class AndroidDemo5Activity extends Activity {
// 定义字符串数组作为提示的文本
String[] books = new String[] { "rollen", "rollenholt", "rollenren", "roll" };
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 创建一个ArrayAdapter封装数组
ArrayAdapter<String> av = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, books);
AutoCompleteTextView auto = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
auto.setAdapter(av);
}
}
热心网友
时间:2023-10-03 03:23
EditView添加onClickListener,在对应的onClick方法里面处理显示逻辑就行了吧
热心网友
时间:2023-10-03 03:23
设置成可点击的,设置监听,然后把你要做的事写进去