android PopupWindow demo

来源:互联网 发布:淘宝特百惠官方旗舰店 编辑:程序博客网 时间:2024/06/06 04:51
public class PopupwindowActivity extends Activity {
LinearLayout ll;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ll = (LinearLayout) findViewById(R.id.container);
    }
    
    
    public void click(View view){
    TextView tv = new TextView(this);
    tv.setTextSize(20);
    tv.setText("哥是弹出窗体");
    tv.setTextColor(Color.RED);
    //PopupWindow popupWindow = new PopupWindow(tv, 100, 100);
    PopupWindow popupWindow = new PopupWindow(tv, 100, 100, true);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    popupWindow.showAtLocation(ll, Gravity.LEFT | Gravity.TOP, 50,100);
    }
}
0 0