我有一个扩展AppCompatActivity的Activity类。 我想让它看起来像一个圆角的对话框。
下面是形状代码
抽拉/ dialog_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#fff"/>
<corners
android:radius="15dp" />
</shape>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
<style name="DialogTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/dialog_bg</item>
<item name="android:windowEnterAnimation">@anim/slide_left</item>
<item name="android:windowExitAnimation">@anim/slide_right</item>
<item name="android:windowIsFloating">true</item>
</style>
</resources>
settings_layout.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:background="@drawable/dialog_bg"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/settingDial"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<!-- Title Bar -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
android:textColor="#FFFFFF"
android:textSize="20dp" />
</LinearLayout>
<!-- Notification -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="15dp"
>
<Switch
android:id="@+id/notificationSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:text="Notification"
android:textSize="15dp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/darker_gray" />
<!-- Notification Time -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="15dp"
android:paddingTop="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:paddingTop="5dp"
android:text="Notification Time"
android:textColor="@android:color/black"
android:textSize="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:text="07:00 AM"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/darker_gray" />
<!-- Music -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="15dp"
>
<Switch
android:id="@+id/Music"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:text="Music"
android:textSize="15dp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/darker_gray" />
<!-- Disable Ads -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:paddingTop="5dp"
android:text="Categories"
android:textColor="@android:color/black"
android:textSize="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:text=">"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/darker_gray" />
<!-- Disable Ads -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:paddingTop="5dp"
android:text="Favorites"
android:textColor="@android:color/black"
android:textSize="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:text=">"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/darker_gray" />
<!-- Disable Ads -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:paddingTop="5dp"
android:text="Disable Ads"
android:textColor="@android:color/black"
android:textSize="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:text=">"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
的AndroidManifest.xml
<activity android:name=".SettingsActivity" android:theme="@style/DialogTheme"/>