3

Here is my XML file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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="#E0E0E0"
android:fitsSystemWindows="true"
tools:context="com.ccb.lldm.lldmhimnario.Cantos">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:elevation="25dp"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimaryDark"
        app:popupTheme="@style/AppTheme.PopupOverlay" />



</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_cantos" />

</android.support.design.widget.CoordinatorLayout>

Here is my Java:

public class Cantos extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cantos);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setLogo(R.mipmap.ic_launcher);
    toolbar.setTitle("Cantos");
    toolbar.setTitleTextColor(getColor(R.color.colorPrimary));

}

}

I was wondering how to add a search to my action bar. So when I input characters, names/objects will come up. Thank you in advance. (Is my XML file correct too?)

2 Answers2

6

Adding a search view is actually very easy in Android as it has inbuilt support for it. Go through the Search view functionality provided by android for more details. http://developer.android.com/guide/topics/search/search-dialog.html

Shashank Udupa
  • 2,173
  • 1
  • 19
  • 26
1

Visit below link, you will find easiest way to implement searchview in action bar http://javapapers.com/android/android-searchview-action-bar-tutorial/

Dharmesh Dhameliya
  • 174
  • 1
  • 3
  • 10