以下のようなxmlファイルがあり、これを使用して背景を設定しますTextview
。
row.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:endColor="#CCCCCC" android:startColor="#CCCCCC"
android:angle="270" />
<stroke android:width="1dp" android:color="#999999" />
<corners android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp" android:topLeftRadius="0dp"
android:topRightRadius="0dp" /></shape>
上記のXmlは、以下のようにmain.xmlでTextViewの背景として設定します。
main.xml
<TextView
android:id="@+id/rowtext3"
android:text="Availablity"
android:layout_height="25px"
android:layout_width="60px"
android:textSize="10px"
android:textStyle="bold"
android:textColor="@color/black"
android:gravity="center"
android:background="@drawable/row"
/>
しかし、これをXmlではなくコードから実行したいと思います。フォント、幅、高さ、フォントなど、Xmlで行ったすべてのことをコードを介して動的に行いましたが、Xmlファイルで言及した背景を設定できません。main.xmlで背景をXMLとして設定する方法と同様に、Xmlファイルのコンテンツを背景としてtextviewに設定するにはどうすればよいですか。
私がこのようにしたコードでは:
t1=new TextView(this); <br>
t1.setText(ed1.getText()); <br>
t1.setHeight(25); <br>
t1.setWidth(60); <br>
t1.setTextSize(10); <br>
しかし、背景を設定する方法、つまりXMLコンテンツを背景として設定する方法が見つかりませんでしたか?
誰かがこの問題を整理するのを手伝ってくれますか?
前もって感謝します、