Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I programmatically set the background color gradient on a Custom Title Bar?
    text
    copied!<p>There are many tutorials out there and questions on SO that implement custom title bars. However, in my custom title bar I have a custom gradient for the background and I would like to know how to set it dynamically in my code.</p> <p>Here is where my custom title bar gets called:</p> <pre><code>requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.foo_layout); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar); </code></pre> <p>And this is my <code>custom_title_bar</code>:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@layout/custom_title_bar_background_colors"&gt; &lt;ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/title_bar_logo" android:gravity="center_horizontal" android:paddingTop="0dip"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>As you can see, the background on the linear layout is defined by this guy:</p> <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;gradient android:startColor="#616261" android:endColor="#131313" android:angle="270" /&gt; &lt;corners android:radius="0dp" /&gt; &lt;/shape&gt; </code></pre> <p>What I would like to do is set those gradient colors dynamically in my code. I do not want to hard code them in my XML file like they currently are.</p> <p>I am open to all ideas if you have a better way of setting a background gradient. </p> <p>Thank you in advance!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload