Code example for LinearLayout

Methods: addViewsetOrientation, setBackgroundColor, setLayoutParams, setPadding

0
    } 
 
    private View createView(final String title, final String message,
            final String uri) {
 
        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setBackgroundColor(0xffeeeeee);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        linearLayout.setPadding(5, 5, 5, 5);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT,
                LinearLayout.LayoutParams.FILL_PARENT);
        linearLayout.setLayoutParams(layoutParams);
 
        TextView textTitle = new TextView(this);
        textTitle.setText(title);
        textTitle.setTextSize(18);
        // textTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); 
        textTitle.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
        textTitle.setTextColor(0xff000000);
        textTitle.setGravity(Gravity.CENTER);
 
        layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(30, 30, 30, 0);
        textTitle.setLayoutParams(layoutParams);
        linearLayout.addView(textTitle);
 
        TextView textDetails = new TextView(this);
        textDetails.setText(message);
        textDetails.setTextSize(14);
        // textTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); 
        textDetails.setTextColor(0xff333333);
        textDetails.setGravity(Gravity.CENTER);
 
        layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(30, 10, 30, 20);
        textDetails.setLayoutParams(layoutParams);
        linearLayout.addView(textDetails);
 
        Button okButton = new Button(this);
        okButton.setText("Ok");
        okButton.setWidth(100);
 
        okButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent intent;
                if (uri != null
                        && uri.length() > 0
                        && (uri.startsWith("http:") || uri.startsWith("https:")
                                || uri.startsWith("tel:") || uri
                                .startsWith("geo:"))) {
                    intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                } else { 
                    intent = new Intent().setClassName(
                            callbackActivityPackageName,
                            callbackActivityClassName);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    // intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
                    // intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); 
                    // intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
                } 
 
                NotificationDetailsActivity.this.startActivity(intent);
                NotificationDetailsActivity.this.finish();
            } 
        }); 
 
        LinearLayout innerLayout = new LinearLayout(this);
        innerLayout.setGravity(Gravity.CENTER);
        innerLayout.addView(okButton);
 
        linearLayout.addView(innerLayout);
 
        return linearLayout;
    } 
 
    //    protected void onPause() {