Android Kotlin App Die Symbolleiste wird nicht angezeigtAndroid

Forum für diejenigen, die für Android programmieren
Anonymous
 Android Kotlin App Die Symbolleiste wird nicht angezeigt

Post by Anonymous »

Ich habe das in der Java -Version arbeiten, aber ich fehlt eindeutig etwas, wenn ich es in Kotlin umschreibe. Ich möchte eine Symbolleiste anstelle der TopApp -Leiste verwenden. In der Dokumentation ist dies alles, was ich zum Laufen bringen muss. /p>

Code: Select all







< /code>
Und hier sind die Funktionen aus der Hauptaktivität.  () < /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()
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post