AutoCompleteTextView的建议框基于用于显示它的方法而有所不同。 理想情况下,两者都应显示键盘上方的框,有任何建议如何修复它?
SearchMusic.axml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="true"
android:background="#fffbbb"
android:padding="16dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatAutoCompleteTextView
android:id="@+id/autoComplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="Music name or artist" />
</android.support.design.widget.TextInputLayout>
</android.support.v4.widget.NestedScrollView>
MainActivity.cs
using Android.App;
using Android.OS;
using Android.Support.Design.Widget;
using Android.Support.V7.App;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using AutoCompleteTextView = Android.Support.V7.Widget.AppCompatAutoCompleteTextView;
using Button = Android.Support.V7.Widget.AppCompatButton;
namespace AutoComplete
{
[Activity(Label = "AutoComplete", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
using (var reader = new StreamReader(Assets.Open("songs.json")))
{
var autoComplete = FindViewById<AutoCompleteTextView>(Resource.Id.autoComplete);
var songs = JsonConvert.DeserializeObject<ICollection<Song>>(reader.ReadToEnd());
autoComplete.Adapter = new SongAdapter(songs);
}
var bottomSheet = FindViewById(Resource.Id.bottomSheet);
var buttonEmbed = FindViewById<Button>(Resource.Id.buttonEmbed);
var buttonFragment = FindViewById<Button>(Resource.Id.buttonFragment);
var bottomSheetBehavior = BottomSheetBehavior.From(bottomSheet);
buttonEmbed.Click += delegate
{
bottomSheetBehavior.State = BottomSheetBehavior.StateExpanded;
};
buttonFragment.Click += delegate
{
var searchMusicFragment = new SearchMusicFragment();
searchMusicFragment.Show(SupportFragmentManager, searchMusicFragment.Tag);
};
}
}
}
SearchMusicFragment
using Android.App;
using Android.Support.Design.Widget;
using Android.Views;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using AutoCompleteTextView = Android.Support.V7.Widget.AppCompatAutoCompleteTextView;
namespace AutoComplete
{
public class SearchMusicFragment : BottomSheetDialogFragment
{
public override void SetupDialog(Dialog dialog, int style)
{
base.SetupDialog(dialog, style);
var view = View.Inflate(Activity, Resource.Layout.SearchMusic, null);
using (var reader = new StreamReader(Application.Context.Assets.Open("songs.json")))
{
var autoComplete = view.FindViewById<AutoCompleteTextView>(Resource.Id.autoComplete);
var songs = JsonConvert.DeserializeObject<ICollection<Song>>(reader.ReadToEnd());
autoComplete.Adapter = new SongAdapter(songs);
}
dialog.SetContentView(view);
//var layout = (CoordinatorLayout.LayoutParams)((View)view.Parent).LayoutParameters;
//var behavior = layout.Behavior;
//if (behavior != null)
// ((BottomSheetBehavior)behavior).SetBottomSheetCallback();
}
}
}