У меня есть это работа в версии Java, но я явно что -то упускаю, когда переписываю его в Котлин. Я хочу использовать панель инструментов, а не панель TopApp. В документацию это все, что мне нужно, чтобы он работал. /p>
< /code>
и вот функции из основной деятельности.
Я также звоню
setsupportactionbar(findviewbyid(r.id.my_toolbar)) и
getSupportActionBar () < /p>
class MainActivity : AppCompatActivity() {
private val REQ_CODE = 111
private lateinit var dialog: AlertDialog
override fun onStart(){super.onStart()}
override fun onPause(){super.onPause()}
override fun onResume() {
super.onResume()
startLocationUpates()
}
override fun onStop(){super.onStop()}
override fun onDestroy(){super.onDestroy()}
override fun onRestart(){super.onRestart()}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setSupportActionBar(findViewById(R.id.my_toolbar))
// getSupportActionBar()
supportActionBar
setContentView(R.layout.main_activity)
//Here be your permissions request, everybody else gets suppressed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val cluckup1 = checkSelfPermission(ACCESS_FINE_LOCATION)
if (cluckup1 != PackageManager.PERMISSION_GRANTED) {
requestPermissions(
arrayOf(
ACCESS_FINE_LOCATION,
ACCESS_COARSE_LOCATION,
INTERNET,
ACCESS_NETWORK_STATE
),
REQ_CODE
)
}
}
dialog = AlertDialog.Builder(this).create()
dialog.setMessage("Give me a few secs...")
dialog.show()
get_location(this)
fusedClient.requestLocationUpdates(locRequest, callback, Looper.getMainLooper())
fusedClient.lastLocation
.addOnSuccessListener { l: Location? ->
if (l != null) {
latitude = l.latitude
longitude = l.longitude
api_location = "${latitude},${longitude}"
use_lat_and_long(this)
getJsonFromAPI(api_location, this)
setContent {
New_WeatherTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) { }
}
}
}
}
}
@SuppressLint("MissingPermission")
private fun startLocationUpates() {
fusedClient.requestLocationUpdates(locRequest, callback, Looper.getMainLooper())
fusedClient.lastLocation
.addOnSuccessListener { l: Location? ->
if (l != null) {
latitude = l.latitude
longitude = l.longitude
}
}
}
//Load up the viewModel using a Factory
fun feed_success(current: Current, forc: Forecast) {
dialog.dismiss()
val queryAPI: QueryAPI by viewModels { QueryAPI.Factory }
val lQueryState = queryAPI.listQueryState.value
lQueryState.currState = current
lQueryState.forcState = forc
val compose_view = ComposeView(this)
setContent{
setComposableContent(lQueryState, compose_view, this)
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.about, menu)
return true
// return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
item.itemId
when (item.itemId) {
R.id.about_app -> {
val a = Intent("app.personal_weather.ABOUT")
a.putExtra("title", "Aboot")
a.putExtra(
"body",
"The weather where you are, with some graphics from http://vclouds.deviantart,"
+ "the responses are from weatherapi.com (Which is only three days, including today)\n"
+ "\nThis is just a test peice that takes your location from the gps and uses it to "
+ "query the weather api. Rotating your device will cause it to reload.\n"
)
startActivity(a)
}
else -> {
super.onOptionsItemSelected(item)
}
}
return false
}
fun feed_failure(e: Exception?) {
dialog.dismiss()
Toast.makeText(this, "Ooops... " + e?.message, Toast.LENGTH_LONG)
.show()
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... ot-showing
Приложение Android Kotlin Панель инструментов не показывает ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1739537932
Anonymous
У меня есть это работа в версии Java, но я явно что -то упускаю, когда переписываю его в Котлин. Я хочу использовать панель инструментов, а не панель TopApp. В документацию это все, что мне нужно, чтобы он работал. /p>
< /code>
и вот функции из основной деятельности.
Я также звоню
setsupportactionbar(findviewbyid(r.id.my_toolbar)) и
getSupportActionBar () < /p>
class MainActivity : AppCompatActivity() {
private val REQ_CODE = 111
private lateinit var dialog: AlertDialog
override fun onStart(){super.onStart()}
override fun onPause(){super.onPause()}
override fun onResume() {
super.onResume()
startLocationUpates()
}
override fun onStop(){super.onStop()}
override fun onDestroy(){super.onDestroy()}
override fun onRestart(){super.onRestart()}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setSupportActionBar(findViewById(R.id.my_toolbar))
// getSupportActionBar()
supportActionBar
setContentView(R.layout.main_activity)
//Here be your permissions request, everybody else gets suppressed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val cluckup1 = checkSelfPermission(ACCESS_FINE_LOCATION)
if (cluckup1 != PackageManager.PERMISSION_GRANTED) {
requestPermissions(
arrayOf(
ACCESS_FINE_LOCATION,
ACCESS_COARSE_LOCATION,
INTERNET,
ACCESS_NETWORK_STATE
),
REQ_CODE
)
}
}
dialog = AlertDialog.Builder(this).create()
dialog.setMessage("Give me a few secs...")
dialog.show()
get_location(this)
fusedClient.requestLocationUpdates(locRequest, callback, Looper.getMainLooper())
fusedClient.lastLocation
.addOnSuccessListener { l: Location? ->
if (l != null) {
latitude = l.latitude
longitude = l.longitude
api_location = "${latitude},${longitude}"
use_lat_and_long(this)
getJsonFromAPI(api_location, this)
setContent {
New_WeatherTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) { }
}
}
}
}
}
@SuppressLint("MissingPermission")
private fun startLocationUpates() {
fusedClient.requestLocationUpdates(locRequest, callback, Looper.getMainLooper())
fusedClient.lastLocation
.addOnSuccessListener { l: Location? ->
if (l != null) {
latitude = l.latitude
longitude = l.longitude
}
}
}
//Load up the viewModel using a Factory
fun feed_success(current: Current, forc: Forecast) {
dialog.dismiss()
val queryAPI: QueryAPI by viewModels { QueryAPI.Factory }
val lQueryState = queryAPI.listQueryState.value
lQueryState.currState = current
lQueryState.forcState = forc
val compose_view = ComposeView(this)
setContent{
setComposableContent(lQueryState, compose_view, this)
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.about, menu)
return true
// return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
item.itemId
when (item.itemId) {
R.id.about_app -> {
val a = Intent("app.personal_weather.ABOUT")
a.putExtra("title", "Aboot")
a.putExtra(
"body",
"The weather where you are, with some graphics from http://vclouds.deviantart,"
+ "the responses are from weatherapi.com (Which is only three days, including today)\n"
+ "\nThis is just a test peice that takes your location from the gps and uses it to "
+ "query the weather api. Rotating your device will cause it to reload.\n"
)
startActivity(a)
}
else -> {
super.onOptionsItemSelected(item)
}
}
return false
}
fun feed_failure(e: Exception?) {
dialog.dismiss()
Toast.makeText(this, "Ooops... " + e?.message, Toast.LENGTH_LONG)
.show()
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79436823/android-kotlin-app-the-toolbar-is-not-showing[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия