这里我有一个AutoCompleteTextView
和一个图像视图; s是一个位于此AutoCompleteTextView
右侧的箭头。当我点击该图片图标时,我需要这个AutoCompleteTextView
处于可编辑状态,这意味着当我们直接触摸此 <AutoCompleteTextView
android:background="@android:color/transparent"
android:id="@+id/auto"
android:textStyle="bold"
android:hint="Select Location"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:dropDownWidth="match_parent"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="dropclick"
android:src="@mipmap/ic_keyboard_arrow_down_black_24dp"/>
</android.support.v7.widget.Toolbar>
public class ViewPagerFragment extends Fragment {
ViewPager viewPager;
PagerAdapter mPagerAdapter;
TabLayout tabLayout;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.myLayout, null);
viewPager = (ViewPager) view.findViewById(R.id.transactions_recharge);
mPagerAdapter = new ViewPagerAdapter(getChildFragmentManager(), 7);
viewPager.setAdapter(mPagerAdapter);
tabLayout = (TabLayout) view.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
return view;
}
class ViewPagerAdapter extends FragmentPagerAdapter {
int pageCount = 0;
String titles[] = {"One", "Two", "Three"};
ViewPagerAdapter(FragmentManager manager, int _pageCount) {
super(manager);
pageCount = _pageCount;
}
@Override
public Fragment getItem(int position) {
if (position == 0) {
//load fragment one
return new FragmentOne();
} else if (position == 1) {
//load fragment two
} else if (position == 2) {
//load fragment three
}
}
@Override
public int getCount() {
return pageCount;
}
@Override
public CharSequence getPageTitle(int position) {
return titles[position];
}
}
}
答案 0 :(得分:0)
您可以使用EditSpinner auto complete spinner lib。
将其添加到gradle:
Content on Top Window is :
<html xmlns:saxon="http://saxon.sf.net/" xmlns="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dot="http://www.volpe.dot.gov" xml:lang="en"><head>
<title>NASS Case Viewer - CaseID:773013618</title>
<link id="StyleOut" type="text/css" rel="stylesheet" title="output" href="StyleOut.css" /><script src="main.js"></script></head>
<body onload="javascript:init('True','/NASS/CDS/XSLT/','773013618','case.xsl','CaseForm','Crash')">
...
...
...
</body></html>
There are 2 frames
Content on menu frame is :
<html xmlns:svg="http://www.w3.org/2000/svg" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:dot="http://www.volpe.dot.gov" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head>
<meta http-equiv="Content-Script-Type" />
<title>menu</title>
...
...
...
</script></head></html>
Content on viewer frame is :
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:svg="http://www.w3.org/2000/svg-20000303-stylable" xmlns:fn="http://www.w3.org/2005/02/xpath-functions"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Case</title>
<link id="StyleOut" type="text/css" rel="stylesheet" title="output" href="StyleOut.css" />
</head>
<body id="bodyMain">
...
...
...
</body></html>
将视图添加到xml文件中:
compile 'com.reginald:editspinner:1.0.0'
准备你的适配器:
<com.reginald.editspinner.EditSpinner
android:id="@+id/autocomplete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:dropDownDrawable="@mipmap/ic_keyboard_arrow_down_black_24dp"
app:dropDownDrawableSpacing="35dp" />
将适配器设置为ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, R.layout.spinner_item, itemList);
:
EditSpinner
答案 1 :(得分:0)
Quessema Aroua的回答很好,但是没有图书馆,你可以做些什么 以XML格式实现此代码。
<AutoCompleteTextView
android:layout_width="0dp"
android:layout_height="30dp"
android:hint="@string/source"
android:id="@+id/actv5"
app:layout_constraintTop_toBottomOf="@+id/actv4"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:background="@drawable/side_nav_bar"
android:textAlignment="center"
android:gravity="center"
android:layout_marginTop="50dp"
android:dropDownHeight="155dp"
android:cursorVisible="false"/>
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:id="@+id/imv2"
android:src="@drawable/ic_keyboard_arrow_down_black_24dp"
app:layout_constraintTop_toTopOf="@+id/actv5"
app:layout_constraintBottom_toBottomOf="@+id/actv5"
app:layout_constraintRight_toRightOf="@+id/actv5"
/>
您可以选择所需的任何布局,但我的ConstraintLayout
这在YourActivity.java
locnames = getResources().getStringArray(R.array.Loc_names);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(
this, android.R.layout.simple_spinner_dropdown_item,
locnames);
autoText1 =(AutoCompleteTextView) findViewById(R.id.actv4);
autoText1.setAdapter(arrayAdapter);
autoText1.setThreshold(1);
autoText1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//autoText1.showDropDown();
hideKeyBoard(view);
//String selection = (String) parent.getItemAtPosition(position);
selected = position;
}
});
/*autoText1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View arg0) {
autoText1.showDropDown(); }
});*/
ImageView imageView = (ImageView) findViewById(R.id.imv1);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View arg0) {
autoText1.showDropDown(); }
});
另外你应该像在我的Strings.XML中那样设置一个locnames字符串,如下所示:
<string-array name="Loc_names">
<item>India</item>
<item>America</item>
<item>Germany</item>
<item>Russia</item>
<item>Australia</item>
<item>China</item>
</string-array>
YourActivity.java代码中的Message部分通过单击AutoCompleteTextView
上的任意位置显示相同的弹出/微调器,这样就无需使用ImageView
(箭头),但您需要ImageView
这就是我将此代码作为消息/评论的原因。
/*autoText1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View arg0) {
autoText1.showDropDown(); }
});*/
由于我直接从我的项目中复制了此内容,您应该根据您的要求更换所有ID /名称。
某些图片供参考