2011-11-16 45 views
2

搜索我试着研究这个了很多天。我真的不知道如何开始做一个非常类似于下面的风格。我知道它包含一个按钮和一个edittext。但是,我不知道如何开始。有人有类似风格的酒吧的示例代码? Androdi search bar style如何做一个酒吧,一个类似的风格在android系统

+2

OT:您截取了截屏工具。大声笑! :) – Mangusto

+0

大声笑>可能是我习惯使用油漆做屏幕截图大声笑 – ericlee

回答

4

Android的搜索栏是本机和自定义元素的混合。

框架/碱/核心/ RES/RES /布局:

通过搜索栏使用的布局可以在机器人的源代码在这个路径(2.1版本,我可以我的硬盘驱动器上)中找到/search_bar.xml

可以发现以下布局的细节:

<view 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    class="android.app.SearchDialog$SearchBar" 
    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> 
</view> 

所有可绘制和样式也都在源代码。

为了让同样的事情,你必须将不同的元素在自己的项目复制。

您可能还来看看不同类别:

  • SearchDialog.SearchBar
  • SearchDialog.SearchAutoComplete
1

我从你的问题假设你想放的EditText和Button与Google搜索一样,并不完全是谷歌搜索实施。在android Activity的主LinearLayout中使用以下片段。

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

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" /> 



    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 
</LinearLayout> 

如果你不是指我的感受,请告诉我。

Regards