Postingan

Menampilkan postingan dari Agustus, 2022

Fix Contextual Action Bar in Fragment

Gambar
To Fix that, very simple: Just include this code in theme.xml, inside of base style.

Remove Back Button When Using Bottom Navigation Bar

Gambar
It's very simple just change appBarConfiguration like this. binding.bottomNavigationView.setupWithNavController(navController) appBarConfiguration = AppBarConfiguration(binding.bottomNavigationView.menu) setupActionBarWithNavController(navController, appBarConfiguration)

Protect API KEY in Android Development

 in build.gradle -> android -> defaultConfig write this code: Properties properties = new Properties() properties.load(project.rootProject.file("local.properties").newDataInputStream()) buildConfigField "String", "API_KEY", "\"${properties.getProperty("API_KEY")}\"" in local.properties , write your api key API_KEY=your_api_key and then sync and rebuild project to use, just called BuildConfig.API_KEY

Styling in Android XML

Learn CRUD with Room Android Kotlin

Gambar
  - setup build.gradle plugins {     id 'kotlin-kapt'     id 'kotlin-parcelize' } buildFeatures {     viewBinding true } dependencies {     implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'     implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'     implementation 'androidx.room:room-runtime:2.3.0'     kapt 'androidx.room:room-compiler:2.3.0' } - create entity @Entity @Parcelize data class Note(     @PrimaryKey(autoGenerate = true)     @ColumnInfo(name = "id")     var id: Int = 0,       @ColumnInfo(name = "title")     var title: String? = null,       @ColumnInfo(name = "description")     var description: String? = null,       @ColumnInfo(name = "date")     var date: String? = null ) : Parcelable - create dao @Dao interface NoteDao {     @Insert(onConflict = OnConflictStra...

Kotlin DataStore

 - apply dependencies implementation "androidx.datastore:datastore-preferences:$latestversion" - create instance prefrences data store val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings") - define preferences datastore key word val EXAMPLE_COUNTER = intPreferencesKey("example_counter") - get value from preferences datastore val exampleCounterFlow: Flow<Int> = context.dataStore.data   .map { preferences ->     // No type safety.     preferences[EXAMPLE_COUNTER] ?: 0 } - saving value suspend fun incrementCounter() {   context.dataStore.edit { settings ->     // get value      val currentCounterValue = settings[EXAMPLE_COUNTER] ?: 0       // edit value      settings[EXAMPLE_COUNTER] = currentCounterValue + 1   } }

Convert HTML to String Android XML

Gambar
To Convert HTML Tag to String XML it was simple, Just use Html.fromHtml() Keep simple!

Change Action Bar Title in Fragment Kotlin

Gambar
  To change action bar title in fragment with kotlin it was simple. just use supportActionBar.title

Consume API with Retrofit

Gambar
 First adding dependencies in build.gradle Make Data Class, based on response api Make Api Service, based on URL API, for example:  https://reqres.in/ api/users ?page=1 Base URL : https://reqres.in/  Endpoint : api/users  Parameter : ?page=1  Create Api Config Last, getting data response using enqueue method.

Methods and Annotation in Retrofit

Gambar
@Headers : adding additional information in header request like Authorization, data type, etc. @Query : add paraneters in @Get method. @Path : adding dynamic variable as endpoint, like {id}. @FormUrlEncoded : mark function on @Post method as form-url-encoded. @Field : pass parameters to the @Post method. @Multipart : marks a function that it is multi-part. @Part : sending files in a multi-part way. @PartMap : sending other data than files on a multi-part.