gpt4 book ai didi

java - 我如何将 BottomNavigationView 放在 中?

转载 作者:行者123 更新时间:2023-11-29 23:31:16 25 4
gpt4 key购买 nike

正如您可能猜到的那样,我是 Android Studio 的初学者。我试图在布局中放置一个 BottomNavigationViewSearchView 需要它,但似乎无法解决。这是我能做的最好的,但 BottomNavigationView 仍然没有出现:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<android.support.v7.widget.SearchView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true" />
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="450dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/search" />


<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
menu="@menu/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
/>
</RelativeLayout>
</layout>

如果有人有任何想法,我很乐意得到一些帮助,在此先感谢!

编辑:这是 Activity - (我将 xml 的名称 activity_main.xml 更改为以便允许我使用绑定(bind))

public class SearchUsers extends AppCompatActivity {
private ActivityMainBinding binding;
ListAdapter adapter;
List<String> arrayList= new ArrayList<>();
private SearchView sv;
private ListView lv;
private MobileServiceClient mService=null;

private MobileServiceTable<users> mTable=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
sv=(SearchView) findViewById(R.id.search);
lv=(ListView)findViewById(R.id.list_view);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
try
{
mService= new MobileServiceClient("https://beyondapplication.azurewebsites.net",SearchUsers.this);

mTable=mService.getTable(users.class);
}
catch (Exception e)
{
Toast.makeText(this, e.getMessage().toString(), Toast.LENGTH_LONG).show();
}

AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... voids) {
try {
List<users> myuser = mTable.execute().get();

if (myuser.size() != 0) {
for (int i=0; i< myuser.size();i++)
{
arrayList.add(myuser.get(i).getName());

}

return true;
} else

return false;

} catch (Exception e) {
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(Boolean answer) {
super.onPostExecute(answer);

if (answer == true) {


} else {

// finish();

}

}
}.execute();



adapter= new MyAdapter(arrayList);

binding.listView.setAdapter(adapter);
binding.search.setActivated(true);
binding.search.setQueryHint("search by username");
binding.search.onActionViewExpanded();
binding.search.setIconified(false);
binding.search.clearFocus();

binding.search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {


return false;
}

@Override
public boolean onQueryTextChange(String newText) {
((MyAdapter) adapter).getFilter().filter(newText);

//String s=binding.search.getQuery().toString();
// if ((binding.search.getQuery().toString().equals("") || binding.search.getQuery().toString().equals(null)|| binding.search.getQuery().toString().equals(" ") && arrayList.size()>0))

return false;
}

});
binding.search.setActivated(true);
binding.search.setQueryHint("search by username");
binding.search.onActionViewExpanded();
binding.search.setIconified(false);
binding.search.clearFocus();

}
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
{
return true;
}
case R.id.profile:
{


}
return true;
case R.id.navigation_notifications:
{
return true;

}
case R.id.find:
startActivity(new Intent(SearchUsers.this, SearchUsers.class));
overridePendingTransition(0, 0);
return true;
}
return false;
}
};

最佳答案

它是工作代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.SearchView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true" />

<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/navigation"
android:layout_below="@+id/search" />

<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/navigation" />
</RelativeLayout>

enter image description here

关于java - 我如何将 BottomNavigationView 放在 <layout> 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52634037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com