Fixed that using vector drawables that way is not supported on devices pre Lollipop

This commit is contained in:
dankito 2020-10-10 02:30:09 +02:00
parent 968543953a
commit eff16876b6
3 changed files with 15 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package net.dankito.banking.ui.android.dialogs.settings
import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import kotlinx.android.synthetic.main.dialog_settings.*
import kotlinx.android.synthetic.main.dialog_settings.view.*
import net.dankito.banking.ui.android.R
@ -55,6 +56,9 @@ open class SettingsDialog : SettingsDialogBase() {
btnSetAppProtection.setOnClickListener { ProtectAppSettingsDialog().show(requireActivity() as AppCompatActivity) }
// on Pre Lollipop devices setting vector drawables in xml is not supported -> set left drawable here
val sendIcon = AppCompatResources.getDrawable(context, R.drawable.ic_baseline_send_24)
btnShowSendMessageLogDialog.setCompoundDrawablesWithIntrinsicBounds(sendIcon, null, null, null)
btnShowSendMessageLogDialog.setOnClickListener { presenter.showSendMessageLogDialog() }
}
}

View File

@ -1,12 +1,14 @@
package net.dankito.banking.ui.android.views
import android.graphics.drawable.Drawable
import android.view.View
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import com.mikepenz.iconics.typeface.library.fontawesome.FontAwesome
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import com.mikepenz.materialdrawer.model.DividerDrawerItem
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem
@ -108,7 +110,7 @@ open class DrawerView(
PrimaryDrawerItem()
.withName(R.string.settings)
.withIcon(R.drawable.ic_baseline_settings_24)
.withIcon(getVectorDrawable(R.drawable.ic_baseline_settings_24))
.withIconColor(ContextCompat.getColorStateList(activity, R.color.primaryTextColor_Dark)!!)
.withSelectable(false)
.withOnDrawerItemClickListener { _, _, _ -> itemClicked { SettingsDialog().show(activity) } }
@ -149,7 +151,7 @@ open class DrawerView(
val accountItem = AccountDrawerItem()
.withName(bank.displayName)
.withLevel(BankLevel)
.withSecondaryIcon(R.drawable.ic_baseline_settings_24)
.withSecondaryIcon(getVectorDrawable(R.drawable.ic_baseline_settings_24))
.withSecondaryIconColor(activity, R.color.primaryTextColor_Dark)
.withOnSecondaryIconClickedListener { closeDrawerAndEditAccount(bank) }
.withIcon(bank.iconData?.toDrawable(activity.resources))
@ -206,4 +208,9 @@ open class DrawerView(
drawerLayout.closeDrawer(GravityCompat.START)
}
private fun getVectorDrawable(@DrawableRes drawableResId: Int): Drawable? {
return AppCompatResources.getDrawable(activity, drawableResId)
}
}

View File

@ -94,14 +94,13 @@
/>
<!-- left drawable is set in code as pre Lollipop devices don't support setting vector drawables in xml -->
<Button
android:id="@+id/btnShowSendMessageLogDialog"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_settings_navigate_to_sub_dialog_button_height"
android:layout_marginTop="@dimen/dialog_settings_navigate_to_sub_dialog_button_margin_top"
style="?android:attr/buttonBarButtonStyle"
android:drawableLeft="@drawable/ic_baseline_send_24"
android:drawableStart="@drawable/ic_baseline_send_24"
android:drawablePadding="@dimen/dialog_settings_button_send_message_log_space_between_icon_and_text"
android:gravity="start|center_vertical"
android:textAlignment="gravity"