点击搜索按钮,弹出搜索框:效果:
代码:
if (i == R.id.book_quer) {//搜索按钮 Dialog dialog = DialogHelper.QueryDialog(CookbookHomeActivity.this, new View.OnClickListener() { @Override public void onClick(View view) { EditText editText=(EditText) view.getTag(); String keyword=editText.getText().toString().trim(); searchStr = keyword; Log.e(TAG,"获取到的值===》"+editText.getText().toString()); //startActivity(new Intent(CookbookHomeActivity.this, CookbooknotActivity.class)); DialogUtil.showRoundProcessDialog(mContext,"数据加载中……",false); QueryBody dataBody = new QueryBody(keyword,"",1,10); BjDataBody body = BJServerBodyUtils.getBjDataBody(dataBody,true); QueryCookPresenter queryCookPresenter=new QueryCookPresenter(CookbookHomeActivity.this); queryCookPresenter.getBookQueryList(HttpAddr.CookBook_URL,body); } }); dialog.show();}
DialogHelper.java
Dialog的Style样式:package util; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import com.haier.delicious_recipe.R; /** * Created by centling on 2016/9/27. */ public class DialogHelper { public static Dialog QueryDialog(Context context, final View.OnClickListener onClickListener){ final Dialog dialog = new Dialog(context,R.style.NoTitleDialogTheme); LayoutInflater inflater = LayoutInflater.from(context); View view = inflater.inflate(R.layout.dialog_query, null); dialog.setContentView(view); final EditText et_quer=(EditText)view.findViewById(R.id.et_quer); ImageView tv_quer=(ImageView)view.findViewById(R.id.tv_quer); tv_quer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(onClickListener!=null){ view.setTag(et_quer); onClickListener.onClick(view); dialog.dismiss(); } } }); // dialog.setView(view, 0, 0, 0, 0); return dialog; } }
<style name="NoTitleDialogTheme" parent="android:Theme.Holo.Light.Dialog"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@color/tran_text</item> <item name="android:windowNoTitle">true</item> </style>