Форум для тех, кто программирует под Android
Anonymous
Как захватить весь экран, включая нижние листы и другие наложения в Android Kotlin?
Сообщение
Anonymous » 11 июл 2024, 16:27
`class BottomSheetDemo: BottomSheetDialogFragment() {
Код: Выделить всё
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.bottom_sheet,container)
view.findViewById(R.id.openButton).setOnClickListener {
captureScreen()
}
return view
}
fun captureScreen(){
val myActivity = activity ?: return
val view = myActivity.window.decorView.rootView
view.isDrawingCacheEnabled = true
view.buildDrawingCache(true)
val bitmap = Bitmap.createBitmap(view.drawingCache)
val file = File(myActivity.cacheDir, "BottomFile.png")
val fOut = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut)
fOut.flush()
fOut.close()
}
}`
Я попробовал приведенный выше код, но он не работает. Может ли кто-нибудь дать какие-нибудь рекомендации?
Подробнее здесь:
https://stackoverflow.com/questions/787 ... verlays-in
1720704425
Anonymous
`class BottomSheetDemo: BottomSheetDialogFragment() { [code]override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val view = inflater.inflate(R.layout.bottom_sheet,container) view.findViewById(R.id.openButton).setOnClickListener { captureScreen() } return view } fun captureScreen(){ val myActivity = activity ?: return val view = myActivity.window.decorView.rootView view.isDrawingCacheEnabled = true view.buildDrawingCache(true) val bitmap = Bitmap.createBitmap(view.drawingCache) val file = File(myActivity.cacheDir, "BottomFile.png") val fOut = FileOutputStream(file) bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut) fOut.flush() fOut.close() } [/code] }` Я попробовал приведенный выше код, но он не работает. Может ли кто-нибудь дать какие-нибудь рекомендации? Подробнее здесь: [url]https://stackoverflow.com/questions/78735828/how-to-capture-the-entire-screen-including-bottom-sheets-and-other-overlays-in[/url]