Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

27.4. 界面操作

27.4.1. findViewById

			
		var frameLayoutDebug = findViewById<FrameLayout>(R.id.frameLayoutDebug)
        frameLayoutDebug.visibility=View.VISIBLE
			
			
			
var textViewBuildType = findViewById<TextView>(R.id.textViewBuildType)
textViewBuildType.text = BuildConfig.BUILD_TYPE + " 内测版"			
			
			

27.4.2. runOnUiThread

Java 用法

			
runOnUiThread(() -> {

});	
			
			

切到 Kotlin

			
	runOnUiThread {
       	qrcodeFrameLayout.visibility = View.VISIBLE
    }			
			
			

27.4.3. Fragment

			
			val transaction = parentFragmentManager.beginTransaction().replace(R.id.fragmentContainerView, SipFullscreenFragment()).addToBackStack(null).setReorderingAllowed(true).commit()
			
			

给 Fragment 传参数,我门定义一个 newInstance 方法。

			
package com.ideasprite.conference.ui.phone

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.ideasprite.conference.R
import com.ideasprite.conference.databinding.FragmentCallFullscreenBinding


class CallFullscreenFragment : Fragment() {
    private lateinit var phoneNumber: String

    private var _binding: FragmentCallFullscreenBinding? = null
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {

        _binding = FragmentCallFullscreenBinding.inflate(inflater, container, false)

        binding.textViewCalledNumber.text = phoneNumber

        binding.imageViewHangup.setOnClickListener {

            val transaction = parentFragmentManager.beginTransaction().replace(R.id.fragmentContainerView, SipFullscreenFragment()).addToBackStack(null).setReorderingAllowed(true).commit()
        }

        return binding.root

    }

    companion object {
        fun newInstance(phoneNumber: String) = CallFullscreenFragment().apply {
            this.phoneNumber = phoneNumber
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}
			
			

			
			val transaction = parentFragmentManager.beginTransaction()
            transaction.replace(R.id.fragmentContainerView, CallFullscreenFragment.newInstance(phoneNumber))//切换fragment 传递 phoneNumber 参数
            transaction.addToBackStack(null)
            transaction.setReorderingAllowed(true)
            transaction.commit()			
			
			

27.4.4. ImageView

27.4.4.1. 设置图片

				
			if (status) {
                phoneBinding?.imageViewLightWifi?.imageResource = R.drawable.stroke_color_rbtn_blue
            } else {
                phoneBinding?.imageViewLightWifi?.imageResource = R.drawable.stroke_color_rbtn_white
            }				
				
				

				
val drawable: Drawable? = ResourcesCompat.getDrawable(resources, R.drawable.myimage, null)