-1
我有一个线性布局谁的背景是一个形状如下面更改popupWindow绘制背景颜色动态
popup_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ff5722"/>
<stroke android:width="3dip" android:color="#FFFFFF" />
<corners android:radius="10dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
上述形状被用作背景的下面布局。
pause_dialog.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="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/pupup_shape"
android:orientation="vertical"
android:weightSum="4">
<TextView
android:id="@+id/txt_puse_scoreTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Score is:"
android:layout_gravity="center"
android:layout_weight="1"
android:textSize="@dimen/abc_text_size_display_1_material"
android:textColor="@android:color/white"/>
<TextView
android:id="@+id/txt_puse_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="70"
android:layout_gravity="center"
android:textAlignment="center"
android:layout_weight="1"
android:textSize="@dimen/abc_text_size_display_2_material"
android:textColor="@android:color/white"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:weightSum="2">
<ImageButton
android:id="@+id/btn_gamePuseRsume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@mipmap/dialog_resum"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_margin="10dp"
android:layout_weight="1"/>
<ImageButton
android:id="@+id/btn_gamePuseExit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@mipmap/dialog_exit"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_margin="10dp"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
这个布局需要用作弹出窗口, 主要的问题,我需要改变这种布局的背景颜色,但它不会改变, 的方式,我正在改变颜色是通过此代码:
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.pause_dialog, null);
final PopupWindow popupWindow = new PopupWindow(popupView, ActionBar.LayoutParams.FILL_PARENT, ActionBar.LayoutParams.WRAP_CONTENT, true);
GradientDrawable drawable = (GradientDrawable) popupView.getResources().getDrawable(R.drawable.pupup_shape);
drawable.setColor(Color.parseColor("#34495e"));
popupWindow.setBackgroundDrawable(drawable);
但是没有什么是改变,如何改变为可绘制背景的颜色?