什么是R.layout.search? [英] What is R.layout.search?
问题描述
我正在创建一个搜索窗口小部件和一个可搜索的活动.我遵循了android开发者指南,并且到目前为止.
I'm creating a search widget and a searchable activity. I followed the android developer guide and have this so far.
这是我的searchableActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
如上所述,R.layout.search正在创建错误.我在布局中没有搜索xml,也无法理解应该在search.xml中定义的内容.
As mentioned, R.layout.search is creating the error. I don't have a search xml in layouts, and I don't understand what I am supposed to define within search.xml.
推荐答案
您需要在res/layout文件夹中具有一个名为search.xml的布局,在其中您将显示搜索结果. 以我为例,我在RecyclerView中显示了搜索结果,这是我的示例布局.
You need to have a layout named search.xml in your res/layout folder where you'll show the search results. I my case I showed the search results in a RecyclerView and here's a sample layout of mine.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_background_search">
<LinearLayout
android:id="@+id/empty_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:tint="@color/color_primary_light"
android:src="@drawable/ic_action_search" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/empty_search_result"
android:textColor="@color/black"
android:textSize="20sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/search_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
这篇关于什么是R.layout.search?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!