2017-03-07 7 views
0

アンドロイドスタジオのテキストボックスに表示される日付ごとに背景画像を変更したいと思います。たとえば、日付が01-Janの場合、背景イメージは1月ごとに表示されます。日付が2月2日の場合、背景画像は2月ごとに表示されます。つまり、毎月背景画像が異なります。月の背景画像を変更する

+0

編集あなたの質問と...あなたの現在のコード進行に –

+1

をご提供あなたの現在のソリューションとどこが詳細に問題を抱えているんを記載してください。 http://stackoverflow.com/help/mcveもお読みください。 – Christopher

+0

回答が役に立ったかどうか教えてください –

答えて

1

毎月の月を取得するには、以下のコードを使用して、別の背景画像

を持っています。その後、その月に基づいて何でもしてください。

Calendar calendar = Calendar.getInstance(); 
    int thisMonth = calendar.get(Calendar.MONTH); 
    String name = getMonth(thisMonth); 
    if(name.equals("Jan")) 
    { 
     View myView = this.findViewById(yourViewId); 
     myView.setBackgroundResource(yourImage);  
    } 
    else if(name.equals("February")) 
    { 
     .... 
    } 

    ...... 

    public static String getMonth(int month){ 
    String[] monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; 
    return monthNames[month]; 
    } 

出典:Change Background Image of RelativeLayout from within Java Class (Android App)

関連する問題