AndroidプログラミングはTextViewフォントの色の設定の方法を実現します。
この例は、AndroidプログラミングによるTextViewフォントの色設定を実現する方法を説明する。皆さんに参考にしてあげます。具体的には以下の通りです。
setTextView(int a)ここのaは色が入る値です。例えば、赤い0 xff0000とは、R.co.lor.redにどのように直接0 xff0000が入ってきたかということです。色を設定する方法はありません。文章の中の第三の方法で資源の色値を先に取ってから送るしかありません。
TextViewのフォント設定方法:
1、直接設定ファイルで設定する
2、Activity類で設定する
第一の方法は簡単で、静的または初期のテキスト色の設定に使用する方法は以下の通りである。
main.xml
二つのところに注意してください。
1、main.xmlのTextViewタグの中:
/redはラベルの下でname値がredの内容を探しています。その時の値は菗FF 0000です。
したがって、ここではこのようにしてもいいです。ラベルを取得することです。
/redとは、ラベルの下で、そのname値がredであるという内容を指す。
このようにして、あなたを信じています。stings.xmlの中ではどうすればいいですか?
次に第二の方式を見ます。Activity類で設定します。
1、まずmain.xmlを次のように変更します。つまりandroidを除く:text Color=「@カラー」:
第二ステップ:TextViewのsetTextColor方式でテキスト色の設定を行います。ここでは3つの方法で設定できます。
第1種:
第3の種類:
setTextView(int a)ここのaは色が入る値です。例えば、赤い0 xff0000とは、R.co.lor.redにどのように直接0 xff0000が入ってきたかということです。色を設定する方法はありません。文章の中の第三の方法で資源の色値を先に取ってから送るしかありません。
tv.setTextColor(this.getResources().getColor(R.color.red));
キーワード:android textviewカラーTextViewのフォント設定方法:
1、直接設定ファイルで設定する
2、Activity類で設定する
第一の方法は簡単で、静的または初期のテキスト色の設定に使用する方法は以下の通りである。
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white"
>
<TextView
android:id="@+id/tv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:autoLink="all"
android:textColor="@color/red"
/>
</LinearLayout>
color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="white">#FFFFFF</drawable>
<drawable name="dark">#000000</drawable>
<drawable name="red">#FF0000</drawable>
</resources>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello"> :https://www.jb51.net/</string>
<string name="app_name"> </string>
</resources>
上で資源の部分を3つの部分に分けました。目的ははっきりしているために、もちろんあなたも一つのxmlファイルを作ってresディレクトリの下に置いてもいいです。そしてファイル名は自由に名付けられます。二つのところに注意してください。
1、main.xmlのTextViewタグの中:
android:textColor="@color/red"
2、color.xml中:#FF0000
@カラーとは、リソースファイル(すべてのresディレクトリの下のxmlファイル)のラベルを取得することを意味します。/redはラベルの下でname値がredの内容を探しています。その時の値は菗FF 0000です。
したがって、ここではこのようにしてもいいです。
android:textColor="@drawable/red"
@drawableとは、資源ファイルの中の/redとは、ラベルの下で、そのname値がredであるという内容を指す。
このようにして、あなたを信じています。stings.xmlの中ではどうすればいいですか?
次に第二の方式を見ます。Activity類で設定します。
1、まずmain.xmlを次のように変更します。つまりandroidを除く:text Color=「@カラー」:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white"
>
<TextView
android:id="@+id/tv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:autoLink="all"
/>
</LinearLayout>
2、ActivityのonCreate方法を修正します。ここで私のActivityはStudy 03_です。01,元のコードは以下の通りです。
package yahaitt.study03_01;
import android.app.Activity;
import android.os.Bundle;
public class Study03_01 extends Activity { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
ステップ1:テキストコントロールTextViewを取得し、tvと名づけます。第二ステップ:TextViewのsetTextColor方式でテキスト色の設定を行います。ここでは3つの方法で設定できます。
第1種:
tv.setTextColor(android.graphics.Color.RED);//
第2の種類:tv.setTextColor(0xffff00ff);//0xffff00ff int
グループで0 xエフ00 ff、0 xは色の整数を表すマークで、ffは透明度を表し、ff 00 ffは色を表します。第3の種類:
tv.setTextColor(this.getResources().getColor(R.color.red));// 。
場合によっては、R.string.redまたはR.drawable.redであっても良いです。もちろん、前提は、対応する構成ファイルに対応する配置を行う必要があります。
<color name="red">#FF0000</color>
<drawable name="red">#FF0000</drawable>
<string name="red">#FF0000</string>
詳細コードは以下の通りです。
package yahaitt.study03_01;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;
public class Study03_01 extends Activity {
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView)this.findViewById(R.id.tv01);
//tv.setTextColor(Color.RED);
//tv.setTextColor(0xff000000);
}
}
ここで述べたように、皆さんのAndroidプログラムの設計に役に立ちます。