Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove black border from inflated layout

I am using PopupWindow, which is working fine, but the problem is after inflating the layout view that is shown with black border.

final PopupWindow popupWindow = new PopupWindow(context);
LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.pop_up_window_menu_layout, null);
popupWindow.setContentView(view);

pop_up_window_menu_layout.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/solid_white"
android:orientation="vertical" >

<TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:gravity="center_vertical"
        android:minHeight="?android:attr/listPreferredItemHeightSmall"
        android:text="SAVE"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:textColor="@color/black"
        android:textSize="@dimen/txt_size_sliding_list" />

I've tried to remove border by using popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)), but problem is still same.

Can anyone tell me how to remove unwanted black border?

like image 605
Buddy Avatar asked Dec 18 '14 20:12

Buddy


2 Answers

I don't see any border around my popup windows, but I do set them up slightly different than you. Hopefully this points you in the right direction.

popup_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="#f5f5f5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <Button
        android:id="@+id/btn_close"
        android:text="Close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
                android:id="@+id/main_view"
                tools:context=".MainActivity">

    <Button
        android:id="@+id/btn_popup"
        android:text="Popup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView
        android:id="@+id/txt_text"
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

MainActivity.java

public class MainActivity extends ActionBarActivity implements View.OnClickListener {

    View popupView;
    Button btnPopup;
    Button btnClose;
    PopupWindow popupWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        popupView = getLayoutInflater().inflate(R.layout.popup_view, null);
        btnClose = (Button) popupView.findViewById(R.id.btn_close);
        btnClose.setOnClickListener(this);

        popupWindow = new PopupWindow(popupView,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);

        btnPopup = (Button) findViewById(R.id.btn_popup);
        btnPopup.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_popup) {
            popupWindow.showAtLocation(findViewById(R.id.main_view), Gravity.NO_GRAVITY, 100, 200);
            //popupWindow.showAsDropDown(btnPopup, 10, 10);
        } else if (v.getId() == R.id.btn_close) {
            popupWindow.dismiss();
        }
    }
}

Screenshot

like image 140
mpkuth Avatar answered Oct 19 '22 14:10

mpkuth


If you getting a black border this means that the default background is set.

this is how you remove it :

popup.setBackgroundDrawable(null);

Try this

like image 35
Parth Anjaria Avatar answered Oct 19 '22 15:10

Parth Anjaria