2017-12-24 14 views
0

アプリケーションのさまざまなインテントの色を変更したいとします。1つのインテントアクションバーの色が赤色で、他のインテントの場合はアクションバーの色が黄色です。 ここに私のAndroidMenifest.xmlがあり、ラベルのテキストを変更しました。 しかし、そのテキスト背景の背景をアプリケーションのメイン画面と同じように変更するにはenter image description hereenter 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. まず、各活動のスタイルを宣言する。[RES /値/の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内で宣言されなければなりません[RES /値/ 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)); 
関連する問題