2017-12-24 7 views
0

응용 프로그램에서 다른 의도의 색을 변경하고 싶습니다. 하나의 의도 작업 막대 색과 같이 빨간색은 빨간색이고 다른 의도는 작업 표시 줄 색이 노란색입니다. 여기에 내 AndroidMenifest.xml에서 레이블 텍스트가 변경되었습니다. 그러나 해당 텍스트 배경의 배경을 응용 프로그램의 주 화면과 동일하게 변경하는 방법 enter image description here. enter image description hereenter image description hereenter image description here응용 프로그램에서 다른 의도의 색 변경

나는 변화를 보았지만 작동하지 않았다. `package com.example.android.miwok;

import android.app.Activity; 
import android.content.Intent; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.view.View; 
import android.widget.TextView; 

public class MainActivity extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    // Set the content of the activity to use the activity_main.xml layout 
file 
    setContentView(R.layout.activity_main); 

    TextView numbers = (TextView) findViewById(R.id.numbers); 

// Set a click listener on that View 
    numbers.setOnClickListener(new View.OnClickListener() { 
     // The code in this method will be executed when the numbers View is 
clicked on. 
     @Override 
     public void onClick(View view) { 
      Intent numbersIntent = new Intent(MainActivity.this, 
NumbersActivity.class); 
      startActivity(numbersIntent); 
      Intent i=new Intent(MainActivity.this,NumbersActivity.class); 
      i.putExtra("toolbarColor", Color.BLUE); 
     } 
    }); 
    TextView family = (TextView) findViewById(R.id.family); 

// Set a click listener on that View 
    family.setOnClickListener(new View.OnClickListener() { 
     // The code in this method will be executed when the family View is 
clicked on. 
     @Override 
     public void onClick(View view) { 
      Intent familyIntent = new Intent(MainActivity.this, 
FamilyMembersActivity.class); 
      startActivity(familyIntent); 
     } 
    }); 
    TextView colors = (TextView) findViewById(R.id.colors); 

// Set a click listener on that View 
    colors.setOnClickListener(new View.OnClickListener() { 
     // The code in this method will be executed when the colors View is 
clicked on. 
     @Override 
     public void onClick(View view) { 
      Intent colorsIntent = new Intent(MainActivity.this, 
ColorsActivity.class); 
      startActivity(colorsIntent); 
     } 
    }); 
    TextView pharses = (TextView) findViewById(R.id.phrases); 

// Set a click listener on that View 
    pharses.setOnClickListener(new View.OnClickListener() { 
     // The code in this method will be executed when the numbers View is 
clicked on. 
     @Override 
     public void onClick(View view) { 
      Intent pharsesIntent = new Intent(MainActivity.this, 
PharsesActivity.class); 
      startActivity(pharsesIntent); 
     } 
    }); 
} 
public void openNumberList(View view){ 
    Intent viewNumber= new Intent(this,NumbersActivity.class); 
    startActivity(viewNumber); 
} 
public void openFamilyMembersList(View view){ 
    Intent viewFamily= new Intent(this,FamilyMembersActivity.class); 
    startActivity(viewFamily); 
} 
public void openPharsesList(View view){ 
    Intent viewPharses= new Intent(this,PharsesActivity.class); 
    startActivity(viewPharses); 
} 
public void openColorsList(View view){ 
    Intent viewColor= new Intent(this,ColorsActivity.class); 
    startActivity(viewColor); 
} 
} 

`

+1

코드 이미지를 공유하지 마시고 여기로 복사하십시오 ... –

+1

다음에 처리 할 것입니다. –

답변

0

당신이 원하는 무엇인가요 변경하려면? 그렇다면 내 단계를 따르십시오. 어떻게해야하는지 알려 드리겠습니다. show_demo

  1. 우선, 각 활동의 스타일을 선언. 입술/값/styles.xml] 그런데

    <?xml version="1.0" encoding="utf-8"?> 
    <resources> 
    
        <!-- other styles ... --> 
    
        <style name="NumbersBg" parent="Theme.AppCompat.Light.DarkActionBar"> 
         <item name="colorPrimary">@color/colorPrimaryNumbers</item> 
         <item name="colorPrimaryDark">@color/colorPrimaryDarkNumbers</item> 
         <item name="colorAccent">@color/colorAccent</item> 
        </style> 
    
        <style name="FamilyMembersBg" parent="Theme.AppCompat.Light.DarkActionBar"> 
         <item name="colorPrimary">@color/colorPrimaryFamilyMembers</item> 
         <item name="colorPrimaryDark">@color/colorPrimaryDarkFamilyMembers</item> 
         <item name="colorAccent">@color/colorAccent</item> 
        </style> 
    
        <style name="ColorsBg" parent="Theme.AppCompat.Light.DarkActionBar"> 
         <item name="colorPrimary">@color/colorPrimaryColors</item> 
         <item name="colorPrimaryDark">@color/colorPrimaryDarkColors</item> 
         <item name="colorAccent">@color/colorAccent</item> 
        </style> 
    
        <style name="PhrasesBg" parent="Theme.AppCompat.Light.DarkActionBar"> 
         <item name="colorPrimary">@color/colorPrimaryPhrases</item> 
         <item name="colorPrimaryDark">@color/colorPrimaryDarkPhrases</item> 
         <item name="colorAccent">@color/colorAccent</item> 
        </style> 
    
    </resources> 
    

    , 상술 한 컬러가 이전 colors.xml 선언되어야 [고해상도/값/colors.xml] :

    <?xml version="1.0" encoding="utf-8"?> 
    <resources> 
    
        <!-- other colors ... --> 
    
        <!-- Numbers --> 
        <color name="colorPrimaryNumbers">#fd8d28</color> 
        <color name="colorPrimaryDarkNumbers">#AE611C</color> 
        <!-- Family Members --> 
        <color name="colorPrimaryFamilyMembers">#3b913c</color> 
        <color name="colorPrimaryDarkFamilyMembers">#2C6B2C</color> 
        <!-- Colors --> 
        <color name="colorPrimaryColors">#87149e</color> 
        <color name="colorPrimaryDarkColors">#4C0C59</color> 
        <!-- Phrases --> 
        <color name="colorPrimaryPhrases">#26afc8</color> 
        <color name="colorPrimaryDarkPhrases">#186D7C</color> 
    
    </resources> 
    
  2. 견적 스타일은 당신의 AndroidManifest.xml에서 이전에 선언했다.

    <?xml version="1.0" encoding="utf-8"?> 
    <manifest> 
        <application> 
    
         <!-- other activities ... --> 
    
         <activity 
          android:name=".NumbersActivity" 
          android:theme="@style/NumbersBg" /> 
    
         <activity 
          android:name=".FamilyMembersActivity" 
          android:theme="@style/FamilyMembersBg" /> 
    
         <activity 
          android:name=".ColorsActivity" 
          android:theme="@style/ColorsBg" /> 
    
         <activity 
          android:name=".PhrasesActivity" 
          android:theme="@style/PhrasesBg" /> 
    
        </application> 
    </manifest> 
    
  3. 실행하십시오.

0

당신은 활동에 추가로 색상을 보낼 수 있습니다.

Intent intent = ..; 
intent.putExtra("toolbarColor", Color.BLUE); 

그리고 활동

당신은 툴바의 색상이

int color = getIntent().getExtra("toolbarColor"); 
toolbar.setBackgroundDrawable(new ColorDrawable(color));