public abstract class SearchTrainCampDialog extends Dialog implements View.OnClickListener{
private EditText et_search;
private Context mContext;
public SearchTrainCampDialog(Context context) {
super(context, R.style.Theme_dialog); // 设置自定义Dialog的风格
this.mContext = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_search_train_camp);
Window window = getWindow();
window.setWindowAnimations(R.style.dialogWindowAnim);
Display disp = window.getWindowManager().getDefaultDisplay();
WindowManager.LayoutParams lp = window.getAttributes();
lp.width = disp.getWidth();
lp.gravity = Gravity.TOP;
window.setAttributes(lp);
et_search = (EditText) findViewById(R.id.et_search);
findViewById(R.id.tv_search).setOnClickListener(this);
findViewById(R.id.tv_cancel).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.tv_search:
String s = et_search.getText().toString();
if(TextUtils.isEmpty(s)){
Toast.makeText(mContext, " 请输入您要搜索的关键字", Toast.LENGTH_SHORT).show();
}else {
search(s);
}
break;
case R.id.tv_cancel:
dismiss();
break;
default:
break;
}
}
public abstract void search(String searchString);
}
<style name="Theme_dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<!-- 边框 -->
<item name="android:windowIsFloating">true</item>
<!-- 是否浮现在activity之上 -->
<item name="android:windowIsTranslucent">false</item>
<!-- 半透明 -->
<item name="android:windowNoTitle">true</item>
<!-- 无标题 -->
<item name="android:windowBackground">@color/transparent</item>
<!-- 背景透明 -->
<item name="android:backgroundDimEnabled">false</item>
<!-- 模糊 -->
</style>
<style name="dialogWindowAnim" parent="android:Animation" mce_bogus = "1">//mce_bogus = "1"动画的震荡频率 加上则会出现弹跳的效果
<item name="android:windowEnterAnimation">@anim/dialog_search_enter_anim</item>
<item name="android:windowExitAnimation">@anim/dialog_search_exit_anim</item>
</style>
dialog_search_enter_anim // 进入动画
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="800"
android:fromAlpha="0"
android:toAlpha="1" />
<translate
android:duration="800"
android:fromYDelta="-100%"
android:toYDelta="0" />
</set>
dialog_search_exit_anim //退出动画
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="800"
android:fromYDelta="0"
android:toYDelta="-100%" />
</set>