回答:
たとえば、android:backgroundプロパティを使用する必要があります。
android:background="@color/white"
また、strings.xmlに白の値を追加する必要があります
<color name="white">#FFFFFF</color>
編集:2012年11月18日
8文字のカラーコードの最初の2文字はアルファ値を提供します。html6文字のカラー表記を使用している場合、色は不透明です。
例:
android:background="@android:color/white"
事前定義されていて、strings.xmlに何も追加する必要がない、さらに使いやすいです。
/res/layout/activity_main.xml
要素android:background
を回答に追加する場所を追加できますか?
あなたも使うことができます
android:background="#ffffff"
xmlレイアウトまたは/res/layout/activity_main.xml
、またはAndroidManifest.xmlのテーマを次のように変更して変更できます
android:theme="@android:style/Theme.Light"
あなたの活動タグに。
背景を動的に変更したい場合は、
YourView.setBackgroundColor(Color.argb(255, 255, 255, 255));
android:background="@android:color/white"
何も定義する必要はありません。で事前定義された色を使用しandroid.R
ます。
context.getResources().getColor(android.R.color.white)
プログラムで可能な限り最も簡単な方法で背景色を変更するには(排他的に-XMLの変更なし):
LinearLayout bgElement = (LinearLayout) findViewById(R.id.container);
bgElement.setBackgroundColor(Color.WHITE);
唯一の要件は、activity_whatever.xmlの「base」要素に、Javaで参照できるIDがあることです(container
この場合)。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
</LinearLayout>
ここで返信したPaschalisとJamesは、コードでTextViewのテキストの色を設定する方法のさまざまな可能性を確認した後、私をこのソリューションに導きました。。
それが誰かを助けることを願っています!
この方法は私にとってうまくいきました:
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.layout.rootLayout);
relativeLayout.setBackgroundColor(getResources().getColor(R.color.bg_color_2));
レイアウトxmlにIDを設定
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rootLayout"
android:background="@color/background_color"
色の値/color.xmlを追加する
<color name="bg_color_2">#ffeef7f0</color>
最も簡単な方法はandroid:background="#FFFFFF"
、layout.xmlまたは/res/layout/activity_main.xml
:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="20sp"
android:background="#FFFFFF">
</TextView>
別の方法として、レイアウト -> .xmlファイル -> デザインビューに移動します。次に、コンポーネントツリーに移動して、色を変更するレイアウトを選択します。以下のコンポーネントツリーには、プロパティセクションがあります。プロパティセクションで背景を選択します(画像セクション1)。次に、図のセクション2をクリックします。次に、[ リソース] ウィンドウが開きます。その色メニューから色を選択し、必要な色を選択します。ここに画像の説明を入力してください
通常は内部で指定されている単純なカラーリソースを使用できます。
res/values/colors.xml.
使用する
<color name="red">#ffff0000</color>
そしてこれを介してこれを使用しandroid:background="@color/red"
ます。この色は、テキストの色など、他の場所でも使用できます。同じ方法でXMLで参照するか、コードで取得します
getResources().getColor(R.color.red).
また、任意のandroid:background="@drawable/mydrawable"
ドローアブルリソースを背景として使用することもできます。これには、9パッチドローアブル、通常のビットマップ、シェイプドローアブルなどを使用します。
アクティビティ全体に背景色を追加したい場合
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1de9b6"
tools:context="com.example.abc.myapplication.MainActivity">
</RelativeLayout>
ビューの背景を使用したい場合
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Andrios"
android:background="@color/colorAccent" />
お役に立てれば!
Androidアプリの背景色をできるだけ簡単に白に変更できるようにしたいと考えています。
parentViewStyle
すべての親ビューに設定します。アクティビティ、フラグメント、ダイアログのほとんどの親ビューと同様に。
<LinearLayout style="@style/parentViewStyle">
... other components inside
</LinearLayout>
ただこのスタイルを中に入れて res>values>styles.xml
<style name="parentViewStyle">
<item name="android:layout_height">match_parent</item>
<item name="android:layout_width">match_parent</item>
<item name="android:background">@color/white</item> // set your color here.
<item name="android:orientation">vertical</item>
</style>
これにより、今後何度も背景色を変更する必要がなくなります。
Kotlinあなたが書いていないだけで、
@色/
好きなものをすばやく簡単に選択できます。
android:background="@color/md_blue_900"