programing

Android 앱에서 배경색을 변경하는 방법

linuxpc 2023. 7. 30. 17:25
반응형

Android 앱에서 배경색을 변경하는 방법

저는 안드로이드 앱에서 배경색을 흰색으로 가장 간단한 방법으로 바꿀 수 있기를 원합니다.

Android:background 속성을 사용해야 합니다.

android:background="@color/white"

또한 strings.xml에 white 값을 추가해야 합니다.

<color name="white">#FFFFFF</color>

편집: 2012년 11월 18일

8자 색상 코드의 처음 두 글자는 알파 값을 제공합니다. HTML 6 문자 색상 표기법을 사용하는 경우 색상이 불투명합니다.

예:

enter image description here

사용할 수도 있습니다.

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.

프로그래밍 방식으로 가능한 가장 간단한 방법으로 배경색을 변경하려면(XML 변경 없음):

LinearLayout bgElement = (LinearLayout) findViewById(R.id.container);
bgElement.setBackgroundColor(Color.WHITE);

유일한 요구 사항은 activity_whating.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>

여기서 대답한 파스칼리스와 제임스는 코드에서 TextView의 텍스트 색상을 설정하는 방법에서 다양한 가능성을 확인한 후 이 솔루션으로 저를 안내합니다.

누군가에게 도움이 되길 바랍니다!

가장 간단한 방법은 다음을 추가하는 것입니다.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>

이 방법은 저에게 효과가 있었습니다.

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>

앱 이미지의 앱 크기를 늘리지 않기 때문에 그라데이션이 있는 배경을 사용하는 가장 좋은 방법은 안드로이드 앱에 독이 되므로 한 가지 색을 배경으로 사용하는 대신 한 가지 배경에 여러 가지 색을 사용할 수 있습니다.

enter image description hereenter image description here

에서 사용할 수 있습니다.xml시트:

android:background="@color/background_color"

레이아웃에서 배경을 변경하려면 이 옵션을 사용합니다.

android:background="@color/your_color"

In Program에서 사용할 수 있습니다.예: Texview 배경색

 TextView tvName = (TextView) findViewById(R.id.tvName);
 tvName.setBackgroundColor(getResources().getColor(R.color.your_color));
  1. Activity_Main.xml로 이동합니다.
  2. 디자인 뷰 / 및 텍스트 뷰가 있습니다.
  3. 텍스트 보기를 선택
  4. 이 코드를 작성합니다.

    android:background="@color/colorAccent"
    

이 코드는 다음과 같이 유용합니다.

android:background="#fff"

저는 안드로이드 앱에서 배경색을 흰색으로 가장 간단한 방법으로 바꿀 수 있기를 원합니다.

질문에 가장 단순한 방법이 나와 있습니다.

세트parentViewStyle모든 부모님의 관점에서.활동, 조각 및 대화상자의 대부분의 상위 보기와 마찬가지로,

<LinearLayout style="@style/parentViewStyle">

  ... other components inside

</LinearLayout>

이 스타일을 안에 넣으면 됩니다.

<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>

이렇게 하면 나중에 배경색을 여러 번 변경할 필요가 없습니다.

당신은 이 방법으로 시도할 수 있습니다.

android:background="@color/white"

일반적으로 내부에 지정된 간단한 색상 리소스를 사용할 수 있습니다.

res/values/colors.xml.

사용하다

<color name="red">#ffff0000</color>

그리고 이것을 사용합니다.android:background="@color/red"이 색상은 텍스트 색상과 같이 다른 곳에서도 사용할 수 있습니다.하거나 XML을 통해 코드로 .

getResources().getColor(R.color.red).

그리기 .android:background="@drawable/mydrawable" (즉, 드로잉 가능, 가능등을 의미). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..

텍스트의 색이 배경과 동일할 때도 있습니다. 목록 보기 속성에 Android:background="#CCCCC"를 입력해 보십시오.

안드로이드:background="#64B5F6"
'#' 뒤의 값은 사용 방법에 따라 자신의 사양이나 필요에 따라 변경할 수 있습니다.
다음은 샘플 코드입니다.

<TextView
        android:text="Abir"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="24sp"
        android:background="#D4E157"  />

감사합니다 :)

코틀린을 위해서 뿐만 아니라, 당신이 글을 쓸 때.

@색상/

원하는 것을 빠르고 간단하게 선택할 수 있습니다.

android:background="@color/md_blue_900"

다른 방법으로 레이아웃 -> .xml 파일 -> 디자인 보기로 이동합니다.그런 다음 구성요소 트리로 이동하여 색상을 변경할 레이아웃을 선택합니다.구성 요소 트리 아래에는 속성 섹션이 있습니다.특성 섹션에서 배경을 선택합니다(그림 섹션 1).그런 다음 그림의 섹션 2를 클릭합니다.그러면 리소스 창이 열립니다.해당 색상 메뉴에서 색상을 선택합니다.그런 다음 원하는 색상을 선택합니다. 여기에 이미지 설명을 입력하십시오.

전체 활동에 배경색을 추가하려면

<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" />

이것이 도움이 되길 바랍니다!

change_color.setBackground(getDrawable(R.color.purple_700));

이 방법은 클릭해서 색상을 변경할 때 효과가 있었습니다.

언급URL : https://stackoverflow.com/questions/2748830/how-to-change-background-color-in-android-app

반응형