Android - Как программно выбрать шейдер? - PullRequest
0 голосов
/ 10 мая 2018

Я реализовал шейдер таким образом, XML-файл называется horde_shader.xml и выглядит следующим образом:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:endColor="@color/bordeaux"
        android:angle="270">
    </gradient>
</shape>

Я также реализовал следующие темы в связанном файле style.xml, который выглядит следующим образом:

<resources xmlns:tools="http://schemas.android.com/tools">

    <style name="AllyTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/royalBlue</item>
        <item name="colorAccent">@color/royalBlue</item>
        <item name="android:navigationBarColor">@color/royalBlue</item>
        <item name="colorShader">@drawable/ally_shader</item>
        <item name="imageFaction">@drawable/ally</item>
        <item name="android:textColorSecondary">@android:color/white</item>
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textColorHint">@android:color/white</item>
        <item name="android:fontFamily">serif</item>
    </style>


    <style name="HordeTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/bordeaux</item>
        <item name="colorAccent">@color/bordeaux</item>
        <item name="android:navigationBarColor">@color/bordeaux</item>
        <item name="colorShader">@drawable/horde_shader</item>
        <item name="imageFaction">@drawable/horde1</item>
        <item name="android:textColorSecondary">@android:color/white</item>
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:fontFamily">serif</item>
    </style>

    <style name="Theme">Theme</style>

    <style name="AppTheme">AppTheme</style>
</resources>

Я попытался в задании установить фон следующим образом:

 <TextView
                android:id="@+id/banner_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Esempio Titolo"
                android:textAlignment="center"
                android:fontFamily="serif"
                android:textColor="#FFF"
                android:paddingBottom="5dp"
                android:background="?attr/colorShader"
                android:layout_alignParentBottom="true"
                android:textSize="17dp"/>
...