編輯:關於Android編程
import java.util.Date; import com.example.exmpopup.util.Utils; import android.app.Activity; import android.os.Bundle; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.TextView; import android.widget.Toast; public class PopupMenuActivity extends Activity implements OnClickListener, OnMenuItemClickListener { private TextView tv_show_menu; private PopupMenu mPopupMenu; private String[] mFormatArray = {"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd", "yyyy年MM月dd日HH時mm分ss秒", "yyyy年MM月dd日"}; private String mFormat = mFormatArray[0]; private Date mNowTime = new Date(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_menu); tv_show_menu = (TextView) findViewById(R.id.tv_show_menu); Button btn_show_menu = (Button) findViewById(R.id.btn_show_menu); btn_show_menu.setOnClickListener(this); mPopupMenu = new PopupMenu(this, btn_show_menu); mPopupMenu.inflate(R.menu.main); //mPopupMenu.getMenuInflater().inflate(R.menu.main, mPopupMenu.getMenu()); mPopupMenu.setOnMenuItemClickListener(this); } @Override public void onClick(View v) { if (v.getId() == R.id.btn_show_menu) { mPopupMenu.show(); } } @Override public boolean onMenuItemClick(MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_refresh) { mNowTime = new Date(); tv_show_menu.setText("當前刷新時間: "+Utils.getFormatDateTime(mNowTime, mFormat)); } else if (id == R.id.menu_about) { Toast.makeText(this, "這個是PopupMenu的演示demo", Toast.LENGTH_LONG).show(); } else if (id == R.id.menu_quit) { finish(); } return true; } }
import java.util.Date; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.view.menu.MenuBuilder; import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu.OnMenuItemClickListener; import android.view.MenuItem; import android.view.SubMenu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import com.example.exmpopup.util.Utils; public class NewPopupMenuActivity extends AppCompatActivity implements OnClickListener, OnMenuItemClickListener { private TextView tv_show_menu_new; private PopupMenu mPopupMenu; private String[] mFormatArray = {"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd", "yyyy年MM月dd日HH時mm分ss秒", "yyyy年MM月dd日"}; private String mFormat = mFormatArray[0]; private Date mNowTime = new Date(); private SubMenu mSubMenu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_menu_new); tv_show_menu_new = (TextView) findViewById(R.id.tv_show_menu_new); Button btn_show_menu_new = (Button) findViewById(R.id.btn_show_menu_new); btn_show_menu_new.setOnClickListener(this); mPopupMenu = new PopupMenu(this, btn_show_menu_new); //mPopupMenu.inflate(R.menu.main); //兩種inflate方式都可以 mPopupMenu.getMenuInflater().inflate(R.menu.main, mPopupMenu.getMenu()); mPopupMenu.setOnMenuItemClickListener(this); mSubMenu = mPopupMenu.getMenu().addSubMenu(0, 999, 9, "更多"); mSubMenu.add(0, 111, 0, "ccc"); mSubMenu.add(0, 112, 1, "cca"); } @Override public void onClick(View v) { if (v.getId() == R.id.btn_show_menu_new) { mPopupMenu.show(); } } @Override public boolean onMenuItemClick(MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_refresh) { mNowTime = new Date(); tv_show_menu_new.setText("當前刷新時間: "+Utils.getFormatDateTime(mNowTime, mFormat)); } else if (id == R.id.menu_about) { Toast.makeText(this, "這個是PopupMenu的演示demo", Toast.LENGTH_SHORT).show(); //點擊“更多”會自動顯示子菜單,點擊“關於”也會由下面代碼來顯示子菜單 mPopupMenu.onOpenSubMenu((MenuBuilder) mSubMenu); } else if (id == 111) { Toast.makeText(this, "您點擊了編號為"+id+"的子菜單項", Toast.LENGTH_SHORT).show(); } else if (id == 112) { Toast.makeText(this, "您點擊了編號為"+id+"的子菜單項", Toast.LENGTH_SHORT).show(); } else if (id == R.id.menu_quit) { finish(); } return true; } }
import android.annotation.TargetApi; import android.app.Activity; import android.os.Build; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListPopupWindow; @TargetApi(Build.VERSION_CODES.KITKAT) public class ListPopupActivity extends Activity implements OnClickListener, OnItemClickListener { private EditText et_list; private ListPopupWindow mPopup; private String[] mGoodArray={"pencil", "potato", "peanut", "carrot", "cabbage", "cat"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); et_list = (EditText) findViewById(R.id.et_list); et_list.setOnClickListener(this); Button btn_show_list = (Button) findViewById(R.id.btn_show_list); btn_show_list.setOnClickListener(this); mPopup = new ListPopupWindow(this); ArrayAdapter adapter = new ArrayAdapter(this, R.layout.spinner_item, mGoodArray); mPopup.setAdapter(adapter); mPopup.setWidth(LayoutParams.WRAP_CONTENT); mPopup.setHeight(LayoutParams.WRAP_CONTENT); mPopup.setModal(true); mPopup.setOnItemClickListener(this); } @Override public void onClick(View v) { if (v.getId() == R.id.et_list) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mPopup.setDropDownGravity(Gravity.END); } mPopup.setAnchorView(v); mPopup.show(); } else if (v.getId() == R.id.btn_show_list) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mPopup.setDropDownGravity(Gravity.START); } mPopup.setAnchorView(v); mPopup.show(); } } @Override public void onItemClick(AdapterView parent, View view, int position, long id) { et_list.setText(mGoodArray[position]); et_list.setSelection(et_list.getText().length()); mPopup.dismiss(); } }
要做這種效果1- 整個自定義控件其實就是一個ArcMenu .(半圓形那一圈),左下角的圖標沒有加入進控件中。 2- 我基於他的類改了點。他是將左下角的關閉ic
我們知道iOS上的應用,狀態欄的顏色總能與應用標題欄顏色保持一致,用戶體驗很不錯,那安卓是否可以呢?若是在安卓4.4之前,答案是否定的,但在4.4之後,谷歌允許開發者自定
翻譯工作耗時費神,如果你覺得本文翻譯得還OK,請點擊文末的“頂”;如有錯訛,敬請指正。謝謝。 Eclip
微信出了電腦版,在收到視頻後,視頻是保存在哪呢?微信電腦版視頻存在哪裡? 微信電腦版視頻文件夾位置就讓下載吧小編來告訴你吧 1、首先我們打開手機上的微信,