activity_main布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}"
android:orientation="vertical">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/recentTab"
style="@style/radioStyle"
android:checked="true"
android:gravity="center"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:text="监控" />
<RadioButton
android:id="@+id/friendTab"
style="@style/radioStyle"
android:gravity="center"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:text="资源" />
<RadioButton
android:id="@+id/noticeTab"
style="@style/radioStyle"
android:gravity="center"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:text="业务" />
</RadioGroup>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索" />
</LinearLayout>
搜索框dialog_search.xml布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#e0e0e0"
android:gravity="right"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_weight="0.07"
android:background="@drawable/edit_text_bg"
android:clickable="true"
android:gravity="center_vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/search" />
<EditText
android:id="@+id/searchEdit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="搜索应用"
android:background="#00000000"
android:imeOptions="actionSearch"
android:paddingLeft="5dp"
android:singleLine="true"
android:textColor="#7f7f7f"
android:textSize="15sp" >
<requestFocus />
</EditText>
</LinearLayout>
<Button
android:id="@+id/cancelButton"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:background="@null"
android:text="取消"
android:textColor="#7f7f7f" />
</LinearLayout>
</LinearLayout>
MainActivity
package com.example.demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
final View contentView = inflater.inflate(R.layout.activity_main, null);
setContentView(contentView);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
SearchDialog dialog = new SearchDialog(MainActivity.this);
dialog.show();
//
// LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
// View view = inflater.inflate(R.layout.dialog_search, null);
// PopupWindow popupWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, true);
// popupWindow.setOutsideTouchable(true);
}
});
}
}
SearchDialog
package com.example.demo;
import android.app.Dialog;
import android.content.Context;
public class SearchDialog extends Dialog {
public SearchDialog(Context context) {
super(context, R.style.searchDialog);
setContentView(R.layout.dialog_search);
setCancelable(true);
}
}
style.xml
<resources>
<style name="radioStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:button">@null</item>
<item name="android:textColor">@color/selector_text_color_main_activity</item>
<item name="android:gravity">center_horizontal|bottom</item>
<item name="android:layout_gravity">bottom</item>
<item name="android:textSize">13sp</item>
<item name="android:paddingBottom">2dp</item>
</style>
<!-- -->
<style name="searchDialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowCloseOnTouchOutside">true</item>
</style>
</resources>