LoginSignup
0
0

More than 3 years have passed since last update.

【備忘録】Androidのステータスバーにグラデーションを指定する

Posted at

画面一面グラデーションなどをやると結構綺麗でした。

Activity.kt

class Activity : AppCompatActivity() {

   override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //好きなグラデーションの向き
        val orientation = GradientDrawable.Orientation.BR_TL
        //好きなグラデーションの色
        val color1 = Color.parseColor("#e5a323")
        val color2 = Color.parseColor("#c4972f")
        val color3 = Color.parseColor("#ac6b25")
        //決めたグラデーションを色が変化する順番に並べる(二色でも良い)
        val colors: IntArray = intArrayOf(color1,color2,color3)

        val gradientDrawable = GradientDrawable(orientation,colors)

        //ステータスバーの背景を透明にする
     window?.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        window?.statusBarColor = Color.TRANSPARENT
        window?.navigationBarColor = Color.TRANSPARENT
        window?.setBackgroundDrawable(gradientDrawable)

        //レイアウトファイルを読み込む
        setContentView(R.layout.activity)
        
        
        

   }


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0