だから私はを拡張するこのクラスを持っていますPopupWindow
。クラスの背景をに設定し、その@android:color/transparent
内容に次のレイアウトを使用します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tips_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dip"
android:orientation="horizontal"
style="?Tips_Background" >
<TextView
android:id="@+id/textInfo"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/register_termsandconditions"
style="?TextAppearance_Footer" />
<ImageButton
android:id="@+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="0dip"
android:layout_gravity="top|right"
android:src="@drawable/btn_dialog_normal"
style="@style/App_ImageButtonStyle" />
</LinearLayout>
アイデアは次のようなポップアップを取得することです:
この効果を実現するために使用するスタイルは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:visible="false">
<gradient
android:startColor="@color/trademark_dark"
android:endColor="@color/trademark_darkest"
android:angle="90" />
<stroke android:width="2dp" android:color="#AAAAAA" />
<corners android:radius="10dp" />
<padding
android:left="8dp"
android:top="8dp"
android:right="8dp"
android:bottom="8dp" />
</shape>
背景がまったく効果がないかのようにウィンドウが完全に透明に見える私のスタートアップアクティビティを除いて、物事は期待どおりに機能しています。
このスタイルを含むテーマを、以下を使用してアプリケーション全体に適用しています。
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/NI_AppTheme.Trademark"
android:name="NApplication">
<activity android:name="LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
....
LoginActivity
私がこの問題に直面している唯一の活動です。何が欠けている可能性がありますか?
アップデート:
@imrankhanによって概説された解決策は機能します。ただし、背景はテーマによって異なるため、直接ハードコードされた参照ではなく、テーマ属性を介してこの値を参照する必要があります。私は試した:
<style name="NI_AppTheme.Trademark">
<item name="Tips_Background">@drawable/application_tips_trademark</item>
</style>
次に、レイアウトを設定しますandroid:background="?Tips_Background"
が、次のスタックトレースでアプリケーションがクラッシュします。
06-25 21:09:36.518: E/AndroidRuntime(874): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01002e a=-1}
06-25 21:09:36.518: E/AndroidRuntime(874): at android.content.res.Resources.loadDrawable(Resources.java:1897)
06-25 21:09:36.518: E/AndroidRuntime(874): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-25 21:09:36.518: E/AndroidRuntime(874): at android.view.View.<init>(View.java:2785)
06-25 21:09:36.518: E/AndroidRuntime(874): at android.view.ViewGroup.<init>(ViewGroup.java:385)
06-25 21:09:36.518: E/AndroidRuntime(874): at android.widget.LinearLayout.<init>(LinearLayout.java:174)
06-25 21:09:36.518: E/AndroidRuntime(874): at android.widget.LinearLayout.<init>(LinearLayout.java:170)