alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Android example source code file (search_bar.xml)

This example Android source code file (search_bar.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Android by Example" TM.

Java - Android tags/keywords

edittext, imagebutton, imageview, inner, linearlayout, outer, searchautocomplete, textview, this

The search_bar.xml Android example source code

<?xml version="1.0" encoding="utf-8"?>
<!--
/* apps/common/res/layout/SearchBar.xml
**
** Copyright 2007, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
**
**     http://www.apache.org/licenses/LICENSE-2.0 
**
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License.
*/
-->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/search_bar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:focusable="true"
    android:descendantFocusability="afterDescendants">

    <!-- Outer layout defines the entire search bar at the top of the screen -->
    <LinearLayout
        android:id="@+id/search_plate"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingLeft="12dip"
        android:paddingRight="12dip"
        android:paddingTop="7dip"
        android:paddingBottom="16dip"
        android:background="@drawable/search_plate_global" >

        <!-- This is actually used for the badge icon *or* the badge label (or neither) -->
        <TextView 
            android:id="@+id/search_badge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="2dip"
            android:drawablePadding="0dip"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorPrimaryInverse" />

        <!-- Inner layout contains the app icon, button(s) and EditText -->
        <LinearLayout
            android:id="@+id/search_edit_frame"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            
            <ImageView
                android:id="@+id/search_app_icon"
                android:layout_height="36dip"
                android:layout_width="36dip"
                android:layout_marginRight="7dip"
                android:layout_gravity="center_vertical"
            />

            <view class="android.app.SearchDialog$SearchAutoComplete"
                android:id="@+id/search_src_text"
                android:background="@drawable/textfield_search"
                android:layout_height="wrap_content"
                android:layout_width="0dip"
                android:layout_weight="1.0"
                android:paddingLeft="8dip"
                android:paddingRight="6dip"
                android:drawablePadding="2dip"
                android:singleLine="true"
                android:ellipsize="end"
                android:inputType="text|textAutoComplete"
                android:dropDownWidth="fill_parent"
                android:dropDownHeight="fill_parent"
                android:dropDownAnchor="@id/search_plate"
                android:dropDownVerticalOffset="-9dip"
                android:popupBackground="@android:drawable/search_dropdown_background"
            />
                
            <!-- This button can switch between text and icon "modes" -->
            <Button 
                android:id="@+id/search_go_btn"
                android:background="@drawable/btn_search_dialog"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
            />

            <ImageButton
                android:id="@+id/search_voice_btn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_marginLeft="8dip"
                android:background="@drawable/btn_search_dialog_voice"
                android:src="@android:drawable/ic_btn_speak_now"
            />
        </LinearLayout>
        
    </LinearLayout>

</LinearLayout>

Other Android examples (source code examples)

Here is a short list of links related to this Android search_bar.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.