windowTitleBackgroundStyle不起作用
我正在尝试将应用程序的窗口标题背景设置为渐变,但是不受影响。因此,请帮助我解决此问题。
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomMenuTitle</item>
</style>
<style name="CustomMenuTitle">
<item name="android:textSize">40dip</item>
<item name="android:background">@drawable/gradient</item>
</style>
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.davud.codeit">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".CodeItActivity"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
最佳答案
使用这种风格
<style name="AppTheme" parent="@android:style/Theme">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomMenuTitle</item>
<item name="android:windowTitleStyle">@style/CustomTitleStyle</item>
<item name="android:windowTitleSize">60dp</item>
</style>
<style name="CustomMenuTitle">
<item name="android:background">@drawable/gradient</item>
</style>
<style name="CustomTitleStyle">
<item name="android:textSize">40dp</item>
<item name="android:textColor">@color/colorblue</item>
</style>
并通过Activity扩展YourActivity
public class YourActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_name);
}
}
关于java - 更改windowTitleBackgroundStyle,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58144880/