編輯:關於android開發
源碼測試示例:
package com.example.popupwindown; import android.os.Bundle; import android.app.Activity; import android.view.Gravity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; import android.widget.Button; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void showWindow(View v){ View view=getLayoutInflater().inflate(R.layout.pop, null); Button button = (Button) view.findViewById(R.id.operate); final TextView textview=(TextView) view.findViewById(R.id.textView1); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { /*Toast.makeText(MainActivity.this, "button is pressed", Toast.LENGTH_SHORT).show();*/ textview.setText("變了"); } }); PopupWindow pop=new PopupWindow(view, LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT); pop.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default)); pop.setAnimationStyle(android.R.style.Animation_Translucent); pop.getBackground().setAlpha(100); pop.setTouchable(true);//如果需要按鈕單擊事件,必須有 pop.setOutsideTouchable(true); pop.setFocusable(true); pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); pop.showAtLocation(v,Gravity.CENTER, 0,0); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
MainActivity.xml布局文件:
<RelativeLayout 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="43dp" android:layout_marginTop="23dp" android:text="彈出窗口" android:onClick="showWindow" /> </RelativeLayout>
還需要一個pop.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="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <Button android:id="@+id/operate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="操作" /> </LinearLayout>
運行結果:
dataBinding與ListView及事件,databinding2015年Google IO大會分布了DataBinding庫,能夠更快捷便利的實現MVVM結構模式
一.TextView 顯示文本框控件, EditText 輸入文本框,.textviewedittext1.一般共有屬性: android:id ----------
更簡單更全的material design狀態欄 從實際使用需要出發,以最簡單的方式實現了幾種類型的MD狀態欄。(重點在fitsSystemWindows的使用) 0
獲取手機通訊錄放入PinnedSectionListView中,按名字首字母排序,並且實現撥打電話功能。,釘釘撥打非通訊錄 1 package com.lixu.ton