Remove black border from bloated layout

I am using PopupWindow which is working fine, but the problem is that after inflating the layout view, its show 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 tried to remove the border using "popupWindow.setBackgroundDrawable (new ColorDrawable (Color.TRANSPARENT)); but the problem remains the same.

Can anyone tell me how to remove the unwanted black border?

+3


source to share


4 answers


I don't see borders around pop-ups, but I differentiate them slightly from you. Hopefully this indicates that you are 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

+2


source


Just try this and let me know ..

Don't forget to create a popup linking to your custom theme:



<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="DialogTheme" parent="android:Theme.Dialog">
        <!-- Fill the screen -->
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>

        <!-- No backgrounds and No titles , and no Window Floating -->
        <item name="android:windowBackground">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">false</item>      

        <!-- Set background what you want-->
        <item name="android:background">#ff0000</item>
    </style>

</resources>

      

+1


source


If you get a black border it means that the default background is set.

this is how you remove it:

popup.setBackgroundDrawable(null);

      

try it

+1


source


This is because you are sending the context inside the popup constructor. -

final PopupWindow popupWindow = new PopupWindow(context);

      

Change this over the popup -

 View popupView = getLayoutInflater().inflate(R.layout.popup_view, null);
PopupWindow popupWindow = new Pop

      

0


source







All Articles