AndroidでListViewアイテムの背景色を変更するにはどうすればよいですか?
この例は、AndroidでListViewアイテムの背景色を変更する方法を示しています。
ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。
ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。
<? xml version= "1.0" encoding= "utf-8" ?> <android.support.constraint.ConstraintLayout xmlns: android = "https://schemas.android.com/apk/res/android" xmlns: tools = "https://schemas.android.com/tools" android :layout_width= "match_parent" android :layout_height= "match_parent" tools :context= ".MainActivity" > <ListView android :id= "@+id/mobile_list" android :layout_width= "match_parent" android :layout_height= "match_parent" /> </android.support.constraint.ConstraintLayout>
ステップ3 −次のコードをsrc / MainActivity.java
に追加しますpackage app.tutorialspoint.com.sample ;
import android.support.v7.app.AppCompatActivity ;
import android.os.Bundle ;
import android.view.View ;
import android.widget.AdapterView ;
import android.widget.ArrayAdapter ;
import android.widget.ListView ;
public class MainActivity extends AppCompatActivity {
String[] mobileArray = { "Android" , "IPhone" , "WindowsMobile" , "Blackberry" ,
"WebOS" , "Ubuntu" , "Windows7" , "Max OS X" } ;
@Override
protected void onCreate (Bundle savedInstanceState) {
super .onCreate(savedInstanceState) ;
setContentView(R.layout. activity_main ) ;
ListView mobileList = findViewById(R.id. mobile_list ) ;
ArrayAdapter adapter = new ArrayAdapter<>( this,
android.R.layout. simple_list_item_1 , mobileArray ) ;
mobileList.setAdapter(adapter) ;
mobileList.setOnItemClickListener( new AdapterView.OnItemClickListener() {
@Override
public void onItemClick (AdapterView<?> parent , View view , int position , long id) {
view.setBackgroundColor(getColor(R.color. colorPrimaryDark )) ;
}
}) ;
}
} ステップ4 −次のコードをandroidManifest.xmlに追加します
<? xml version= "1.0" encoding= "utf-8" ?> <manifest xmlns: android = "https://schemas.android.com/apk/res/android" package= "app.tutorialspoint.com.sample" > <application android :allowBackup= "true" android :icon= "@mipmap/ic_launcher" android :label= "@string/app_name" android :roundIcon= "@mipmap/ic_launcher_round" android :supportsRtl= "true" android :theme= "@style/AppTheme" > <activity android :name= ".MainActivity" > <intent-filter> <action android :name= "android.intent.action.MAIN" /> <category android :name= "android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 android studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[実行]アイコンをクリックします。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します–
-
Tkinterリストボックスの色を完全に変更するにはどうすればよいですか?
Tkinterリストボックスウィジェットは、大量のデータアイテムをリストアイテムの形式で表す場合に非常に便利です。リストボックス全体の背景色を変更するなどのプロパティを構成するには、 configure(** options)を使用できます。 リストボックスウィジェットのプロパティを変更するメソッド。 例 # Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.
-
iOSでノートの背景色を変更する方法
iOSでメモアプリを使用している場合は、デバイスの設定に基づいて無地の背景を使用することを嫌うでしょう。ライトモードを有効にしている場合、ダークモードを使用している間は明るい背景と暗い背景が表示されます。ただし、iOSではメモの背景色を簡単に変更できます。これがその方法です。 注 :Notesアプリで別のバックグラウンドを有効にするには、デバイスが少なくともiOS 13 /iPadOS13以降を実行していることを確認する必要があります。そうでない場合は、続行する前にデバイスを最新のファームウェアに更新してください。 特定のメモの背景を変更する 1.デバイスでNotesアプリを開きます。