Java 使用样式设置背景
如何使用styles.xml设置布局可绘制背景?在布局中,我使用了2个可绘制按钮 当我在styles.xml中使用此选项时,所有按钮都会将背景更改为styles中的内容,但我只想更改布局背景Java 使用样式设置背景,java,android,background,styles,Java,Android,Background,Styles,如何使用styles.xml设置布局可绘制背景?在布局中,我使用了2个可绘制按钮 当我在styles.xml中使用此选项时,所有按钮都会将背景更改为styles中的内容,但我只想更改布局背景 <style name="menutheme"> <item name="android:background">@drawable/menu</item> </style> @可绘图/菜单 我的布局: <android.support.c
<style name="menutheme">
<item name="android:background">@drawable/menu</item>
</style>
@可绘图/菜单
我的布局:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/menutheme"
android:contentDescription="@null"
tools:context="com.example.user.app.Activity2">
<RelativeLayout
android:layout_width="312dp"
android:layout_height="371dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.955">
<Button
android:id="@+id/entrycity"
android:layout_width="243dp"
android:layout_height="65dp"
android:layout_below="@+id/button3"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:background="@drawable/oval3"
android:fontFamily="@font/ultra"
android:text="@string/wybor2"
android:textColor="@android:color/background_light"
android:textSize="30sp"
tools:layout_editor_absoluteX="59dp"
tools:layout_editor_absoluteY="334dp" />
<Button
android:id="@+id/button3"
android:layout_width="243dp"
android:layout_height="65dp"
android:layout_alignParentTop="true"
android:layout_alignStart="@+id/entrycity"
android:background="@drawable/oval"
android:fontFamily="@font/ultra"
android:text="@string/wybor"
android:textColor="@android:color/background_light"
android:textSize="30sp"
tools:layout_editor_absoluteX="71dp"
tools:layout_editor_absoluteY="227dp" />
</RelativeLayout
</android.support.constraint.ConstraintLayout>
尝试WindowBackground
而不是background。像
<style name="menutheme" parent="AppTheme">
<item name="android:windowBackground">@drawable/menu</item>
</style>
@可绘图/菜单
您需要将此主题应用于清单中的活动。而不是布局。我想为每个布局设置不同的背景,那么为什么要使用主题来提供背景呢?直接将背景应用于布局。