編輯:關於Android編程
如果做一個如下圖的Dialog,首先要定義樣式:
public abstract class DropDownFilterDialog extends Dialog { protected ArrayListmTopMenuList; OnDropdownClickListener mDropdownClickListener; protected LinearLayout mDropDownMenuLayout; public Context mContext; private int mCurrentIndex = 0; public void setCurrentIndex(int mCurrentIndex) { this.mCurrentIndex = mCurrentIndex; } public void setTopMenuItemList(ArrayList mTopMenuList) { this.mTopMenuList = mTopMenuList; } public DropDownFilterDialog(Context context) { super(context, R.style.DropdownFilterDialogStyle); mContext = context; } public interface OnDropdownClickListener { void onDropdownHide(); void onClickItem(int index); } public void setDropDownClickListener(OnDropdownClickListener dropdownClickListener) { mDropdownClickListener = dropdownClickListener; } public abstract void hideDropDownFilter(boolean showAnimation); public abstract void showDialog(boolean showAnimation, View banner); public void init() { mDropDownMenuLayout = (LinearLayout) findViewById(R.id.text_chat_menu_linear); constructButton(mTopMenuList); } @Override protected void onStart() { super.onStart(); init(); } public void constructButton(ArrayList list) { mDropDownMenuLayout.removeAllViews(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); // mDropDownMenuLayout.addView(View.inflate(mContext, // R.layout.view_top_menu_separator, null), params); final int size = list.size(); final int lastPosition = size - 1; for (int i = 0; i < size; i++) { DropDownItem item = list.get(i); View view = View.inflate(mContext, R.layout.dropdown_menu_item_layout, null); view.setTag(i); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { hideDropDownFilter(true); mDropdownClickListener.onClickItem((Integer) view.getTag()); } }); TextView btn = (TextView) view .findViewById(R.id.top_menu_button); btn.setText(item.getName()); btn.setTag(item.getIndex()); if (mCurrentIndex == i) { btn.setTextColor(mContext.getResources().getColor(R.color.contact_detail_phone_related_color_pressed)); } TextView tab_indicator_counter = (TextView) view.findViewById(R.id.indicator_counter); if (item.getCouter() == 0) { tab_indicator_counter.setVisibility(View.GONE); } else { tab_indicator_counter.setText(String.valueOf(item.getCouter())); } boolean showSeparator = true; if (size == 1) { showSeparator = false; } else if (i == lastPosition) { showSeparator = false; } view.setBackgroundResource(R.drawable.drop_down_filter_item_background_selector); mDropDownMenuLayout.addView(view, params); if (showSeparator) { LinearLayout.LayoutParams paramsForLine = new LinearLayout.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, mContext.getResources().getDimensionPixelSize(R.dimen.top_menu_vertical_separator)); paramsForLine.leftMargin = mContext.getResources().getDimensionPixelSize(R.dimen.drop_down_menu_item_margin_left_right); paramsForLine.rightMargin = paramsForLine.leftMargin; mDropDownMenuLayout.addView(View.inflate(mContext, R.layout.drop_down_menu_divider_layout, null), paramsForLine); } } mDropDownMenuLayout.invalidate(); } }
然後是具體實現類:
public class DropDownFilterDialogForTablet extends DropDownFilterDialog { public DropDownFilterDialogForTablet(Context context) { super(context); mContext = context; Window window = getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.drop_down_filter_dialog); } @Override protected void onStart() { super.onStart(); init(); } public void hideDropDownFilter(boolean showAnimation) { dismiss(); mDropdownClickListener.onDropdownHide(); } public void init() { super.init(); mDropDownMenuLayout.setBackgroundResource(R.drawable.dropdown_filters_background); } public void showDialog(boolean showAnimation, View banner) { Window window = getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); int height = mContext.getResources().getDimensionPixelSize(R.dimen.drop_down_menu_item_margin_top_for_tablet); if (banner == null) { lp.y = height; } else { lp.y = height + banner.getMeasuredHeight(); } show(); } @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { hideDropDownFilter(true); return true; } return false; } @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_BACK) { hideDropDownFilter(true); return true; } return super.dispatchKeyEvent(event); } }
前言研究了一段時間的藍牙使用,發現網上相關的資料比較貧乏,不像其他Android相關資料那麼齊全,基本上大部分資料都是在藍牙聯盟SIG提供的官網https://www.b
android中使用jni對字符串加解密實現分析 最近項目有個需求,就是要對用戶的敏感信息進行加密處理,比如用戶的賬戶密碼,手機號等私密信息。在java中,就對字符串
Android Studio 打包及引用 aar1、 簡述在比較大的 Android 項目的開發中,我們經常會遇到工程、jar 包等等之間相互引用的方式。一般我們通過在
在配置好NDK開發之後就可以使用C/C++開發android了。下面以一個HelloWorld項目來說明1.新建一個Android工程新建一個HelloWorld工程代碼