i am student, still exploring the android studio with few guides from youtube, i was wondering if i could customize icons/vector in a bottom navigation bar? initially, i made a mockup of how the navbar would look like mockup bottom navbar, and i have tried a tutorial from youtube, and this is the result, i get that it was imported as a vector asset that's why the colors changed but i tried converting it to .svd and this is how it looks like .svd conversion, is there any way i can customize it without losing the format of the icons? also, i have tried changing the font in themes.xml, however, the text went at the top of the icons, the result before putting a custom font family is like this, is there any way i could also make the text of each item appear at once? like the one i showed in the mockup. i apologize for these questions if it looked so simple to resolve but i am having a hard time finding the right solution :')
below are the codes
bottom_nav_menu.xml
<item android:title="Home"
android:icon="#drawable/homebtn"
android:id="#+id/homebtn"/>
<item android:title="Courses"
android:icon="#drawable/coursebtn"
android:id="#+id/coursebtn"/>
<item android:title="Challenges"
android:icon="#drawable/challengesbtn"
android:id="#+id/challengesbtn"/>
<item android:title="Flashcards"
android:icon="#drawable/flashcardsbtn"
android:id="#+id/flashcardsbtn"/>
<item android:title="Dictionary"
android:icon="#drawable/dictionarybtn"
android:id="#+id/dictionarybtn"/>
activity_main.xml
<FrameLayout
android:id="#+id/frame_layout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/bottom_nav_menu"
android:theme="#style/Widget.BottomNavigationView"
android:background="#40B191"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
MainActivity.class
ActivityMainBinding binding;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView((binding.getRoot()));
replaceFragment(new HomeFragment());
binding.bottomNavigationView.setOnItemSelectedListener(item -> {
switch (item.getItemId()) {
case R.id.homebtn:
replaceFragment(new HomeFragment());
break;
case R.id.coursebtn:
replaceFragment(new CoursesFragment());
break;
case R.id.challengesbtn:
replaceFragment(new ChallengesFragment());
break;
case R.id.flashcardsbtn:
replaceFragment(new FlashcardsFragment());
break;
case R.id.dictionarybtn:
replaceFragment(new DictionaryFragment());
break;
}
return true;
});
}
private void replaceFragment(Fragment fragment){
//To load the fragments
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_layout, fragment);
fragmentTransaction.commit();
}
}
themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.SALITONGUE_UPDATED" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<!-- Font Family. -->
<style name="Widget.BottomNavigationView"
parent="Widget.Design.BottomNavigationView">
<item name="fontFamily">#font/fredoka</item>
<item name="android:textSize">10sp</item>
</style>
I am using a custom actionbar view, and as you can see in the screenshot below, there is a blank gray space in the actionbar. I want to remove it.
What have I done:
res/values-v11/styles.xml
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
<item name="actionBarStyle">#style/ActionBarStyle</item>
</style>
res/values/my_custom_actionbar.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:height">60dp</item>
</style>
</resources>
Manifest
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/AppName"
android:theme="#style/AppBaseTheme" >
<!-- activities... etc -->
</application>
MainActivity
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
ActionBar actionbar = getSupportActionBar();
actionbar.setDefaultDisplayHomeAsUpEnabled(false);
actionbar.setDisplayHomeAsUpEnabled(false);
actionbar.setDisplayShowCustomEnabled(true);
actionbar.setDisplayShowHomeEnabled(false);
actionbar.setDisplayShowTitleEnabled(false);
actionbar.setDisplayUseLogoEnabled(false);
actionbar.setHomeButtonEnabled(false);
// Add the custom layout
View view = LayoutInflater.from(this).inflate(R.layout.actionbar, null, false);
actionbar.setCustomView(view);
}
I have found a recent post, that is pointing out that there is an issue with the latest release. I have also updated ADT and SDK to Android 5.
Android ActionBar's custom view not filling parent
I don't know what should I do.
Edit (partial solution):
Not working on Android <= API 10.
Android Lollipop, AppCompat ActionBar custom view doesn't take up whole screen width
What have I changed:
Use the latest sdk version:
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21" />
Add a toolbarStyle:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
<item name="actionBarStyle">#style/ActionBarStyle</item>
<item name="android:toolbarStyle">#style/ToolbarStyle</item>
<item name="toolbarStyle">#style/ToolbarStyle</item>
</style>
<style name="ToolbarStyle" parent="#style/Widget.AppCompat.Toolbar">
<item name="contentInsetStart">0dp</item>
<item name="android:contentInsetStart">0dp</item>
</style>
If you are adding the Toolbar via XML, you can simply add XML attributes to remove content insets.
<android.support.v7.widget.Toolbar
xmlns:app="schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primaryColor"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp" />
try this:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
View customView = getLayoutInflater().inflate(R.layout.main_action_bar, null);
actionBar.setCustomView(customView);
Toolbar parent =(Toolbar) customView.getParent();
parent.setPadding(0,0,0,0);//for tab otherwise give space in tab
parent.setContentInsetsAbsolute(0,0);
The left inset is caused by Toolbar's contentInsetStart which by default is 16dp.
Change this to align to the keyline.
Update for support library v24.0.0:
To match the Material Design spec there's an additional attribute contentInsetStartWithNavigation which by default is 16dp. Change this if you also have a navigation icon.
It turned out that this is part of a new Material Design Specification introduced in version 24 of Design library.
https://material.google.com/patterns/navigation.html
However, it is possible to remove the extra space by adding the following property to Toolbar widget.
app:contentInsetStartWithNavigation="0dp"
Before :
After :
I found an other resolution (reference appcompat-v7 ) that change the toolbarStyle ,following code:
<item name="toolbarStyle">#style/Widget.Toolbar</item>
<style name="Widget.Toolbar" parent="#style/Widget.AppCompat.Toolbar">
<item name="contentInsetStart">0dp</item>
</style>
Just add app:contentInsetStart="0dp" to the XML attribute of the toolbar.
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:paddingLeft="0dp">
This should be good enough.
Just Modify your styles.xml
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar">
<item name="contentInsetStart">0dp</item>
<item name="contentInsetEnd">0dp</item>
</style>
Only add app:contentInsetStart="0dp" to the toolbar remove that left space.
So your Toolbar definition look like this
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
app:contentInsetStart="0dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
and it look like this
Instead of adding a toolbar in the layout, you can set your custom view as shown below.
Toolbar parent = (Toolbar) customView.getParent();
parent.setContentInsetsAbsolute(0,0);
If you check the documentation of toolbar, by default it has style defined and there is an item contentInsetStart.
<item name="contentInsetStart">16dp</item>
If you want to override this padding then it can be done in two ways.
1.Override the style and add your own style with contentInsetStart and contentInsetEnd values
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar">
<item name="contentInsetStart">0dp</item>
<item name="contentInsetEnd">0dp</item>
</style>
2.In XML you can directly define the contentInsetStart and contentInsetEnd values
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:layout_height="?attr/actionBarSize">
<!--Add your views here-->
</androidx.appcompat.widget.Toolbar>
Using AppCompatAcitivty you can use just by
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
View logo = getLayoutInflater().inflate(R.layout.custom_toolbar, null);
mToolbar.addView(logo, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mToolbar.setContentInsetsAbsolute(0,0);
You need to add this line app2:contentInsetStart="0dp" in your toolbar
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app2="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app2:contentInsetStart="0dp"/>
this work for me
toolbar.setPadding(0,0,0,0);
toolbar.setContentInsetsAbsolute(0,0);
Setting "contentInset..." attributes to 0 in the Toolbar didn't work for me. Nilesh Senta's solution to update the style worked!
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="actionBarStyle">#style/Actionbar</item>
<item name="android:titleTextStyle">#style/ActionbarTitle</item>
</style>
<style name="Actionbar" parent="Widget.AppCompat.ActionBar">
<item name="contentInsetStart">0dp</item>
<item name="contentInsetEnd">0dp</item>
</style>
java (onCreate)
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT
);
View view = LayoutInflater.from(this).inflate(R.layout.actionbar_main, null);
actionBar.setCustomView(view, layoutParams);
In xml add these two attribute for Toolbar tag:
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
and inside code add these lines:
// remove extra padding of toolbar
toolbar.setContentInsetsAbsolute(0, 0);
toolbar.setPadding(0, 0, 0, 0);
Tested on mobile and tablet devices both.
Kotlin
supportActionBar?.displayOptions = ActionBar.DISPLAY_SHOW_CUSTOM;
supportActionBar?.setCustomView(R.layout.actionbar);
val parent = supportActionBar?.customView?.parent as Toolbar
parent?.setPadding(0, 0, 0, 0)//for tab otherwise give space in tab
parent?.setContentInsetsAbsolute(0, 0)
I did not find a solution for my issue (first picture) anywhere, but at last I end up with a simplest solution after a few hours of digging. Please note that I tried with a lot of xml attributes like app:setInsetLeft="0dp", etc.. but none of them helped in this case.
Picture 1
the following code solved this issue as in the Picture 2
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//NOTE THAT: THE PART SOLVED THE PROBLEM.
android.support.design.widget.AppBarLayout abl = (AppBarLayout)
findViewById(R.id.app_bar_main_app_bar_layout);
abl.setPadding(0,0,0,0);
}
Picture 2
Create toolbar like this:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/menuToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="#color/white"
android:contentInsetLeft="10dp"
android:contentInsetRight="10dp"
android:contentInsetStart="10dp"
android:minHeight="?attr/actionBarSize"
android:padding="0dp"
app:contentInsetLeft="10dp"
app:contentInsetRight="10dp"
app:contentInsetStart="10dp"></android.support.v7.widget.Toolbar>
please follow this link for more - Android Tips
only adding android:padding="0dp" work for me
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="60dp"
android:padding="0dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
ActionBar ab = getSupportActionBar();
ab.setDisplayShowHomeEnabled(true);
ab.setDisplayShowCustomEnabled(true);
setDisplayShowTitleEnabled(true);
View customView = getLayoutInflater().inflate(R.layout.activity_main,null); //here activity_main.xml is the GUI design file.
ab.setCustomView(customView);
Toolbar parent =(Toolbar) customView.getParent(); //use V7 Toolbar import
parent.setContentInsetsAbsolute(0, 0);
setPadding(5,0,0,0);
ab.setIcon(R.mipmap.ic_launcher);
You can just use relative layout inside toolbar view group in your xml file and adjust the positions of widgets as you require them for your use case.No need to create custom layout & inflate it and attach to toolbar. Once done in your java code use setContentInsetsAbsolute(0,0) with your toolbar object before setting it as support action bar in your layout.
It would be better to add a background item into the style of the app actionbar to consistent with the background color of the customized actionbar:
<item name="android:background">#color/actionbar_bgcolor</item>
After android 6.0, the actionbar even has a margin-right space and cannot be set. Add a right margin adjusting in the activity like this: (the view is the customized actionbar or a right button in it)
int rightMargin = Build.VERSION.SDK_INT>=Build.VERSION_CODES.M ? 0 : 8; // may the same with actionbar leftMargin in px
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
p.setMargins(p.leftMargin, p.topMargin, rightMargin, p.bottomMargin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
p.setMarginEnd(rightMargin);
}
view.setLayoutParams(p);
The actionbar machenism is just supported after Android 3.0+ app. If we use a toolbar (of support lib v7) instead, we should layout it in each xml of each activity, and take care of the issue of overlapping with system status bar in the Android 5.0 or later device.
I have an activity (MainActivity.java) that is used as the launch screen while the main fragment is being loaded and other functionality takes place in background. This launch screen shows a brown tile background and an icon always. What I want is to show that backgound (in R.style.AppTheme_NoActionBar_LauncherNight) only when the variable dayMode is false (variable in Constants.java). Otherwise, the background should be the one in R.style.AppTheme_NoActionBar_LauncherDay (a white background and the same icon).
If I specify one or another background in the android:theme part of my Manifest, it is shown nicely. But what I want is to set one theme or another programmatically, depending on the value of dayMode, on the onCreate method of the activity. This is what is not working.
I tried using setTheme before calling super.onCreate or setContentView, as I read in other answers, but it is not working. I only find answers explaining the order in which you should call setTheme and setContentView, but they do not solve this problem.
My styles:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="autoCompleteTextViewStyle">#style/cursorColor</item>
<item name="android:textColorSecondary">#color/yellow_light</item>
</style>
<style name="AppTheme.NoActionBar.LauncherNight">
<item name="android:windowBackground">#drawable/launch_screen</item>
</style>
<style name="AppTheme.NoActionBar.LauncherDay">
<item name="android:windowBackground">#drawable/launch_screen_day</item>
</style>
My Manifest:
<activity
android:name="com.AlbaRam.myApp.MainActivity"
android:configChanges="keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar.LauncherNight"
android:launchMode="singleInstance"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
My ActivityMain:
#Override
protected void
onCreate(Bundle savedInstanceState) {
//This is not working
if (Constants.dayMode){
super.setTheme(R.style.AppTheme_NoActionBar_LauncherDay);
} else {
setTheme(R.style.AppTheme_NoActionBar_LauncherNight);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//rest of functionality
}
After some research I've discovered that this is not possible. Launch screens are used when we want to show something while our main functionality is loading, so we include the drawable we want to show in the Manifest to have this appearing fast while our main activity loads. This launch screen, as it is in the Manifest, appears before anything else, so if we could change the theme of the launch screen dinamically, we would lose that fast appearing while everything else loads.
Try this code
theme.xml
<resources>
<style name="AppThemeLight" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:windowAnimationStyle">#style/WindowAnimationTransition</item>
</style>
<style name="AppThemeDark" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="android:windowAnimationStyle">#style/WindowAnimationTransition</item>
</style>
<!-- This will set the fade in animation on all your activities by default -->
<style name="WindowAnimationTransition">
<item name="android:windowEnterAnimation">#android:anim/fade_in</item>
<item name="android:windowExitAnimation">#android:anim/fade_out</item>
</style>
activity
#Override
protected void onCreate(Bundle savedInstanceState) {
AppSettings settings = AppSettings.getInstance(this);
setTheme(settings.getBoolean(AppSettings.Key.USE_DARK_THEME) ? R.style.AppThemeDark : R.style.AppThemeLight);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transition_theme);
//
}
public void onCreate(Bundle savedInstanceState) {
if (Constants.dayMode){
setTheme(android.R.style.yourTheme);
} else {
setTheme(android.R.style.yourTheme);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.actvity);
}
I have an activity_login.xml with a FrameLayout in Android Studio, which doesn't appear in fullscreen mode with this configuration:
AndroidManifest.xml:
<activity
android:name=".Activities.LoginActivity"
android:label="#string/title_activity_login"
android:launchMode="singleTop"
android:theme="#style/LoginScreenTheme.TranslucentBar" >
</activity>
Styles.xml:
<style name="LoginScreenTheme.TranslucentBar" parent="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
The Toolbar is still appearing in the Layout.
Look at your activity Layout, most likely there is Toolbar view that AndroidStudio generated for you. If that does not work add to the style:
<item name="android:windowFullscreen">true</item>
Modify onCreateView() as below
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
In order to remove the Toolbar/ActionBar you don't need to do anything special at all. Just keep everything as default and go to the styles.xml and change the AppTheme to Theme.AppCompat.Light.NoActionBar and also make sure that your activity extends AppCompactActivity. It always works for me. Hope it will help you as well. And if you also wants to remove the StatusBar then follow #EKN solution above ;)
I don't do anything and today when I started my project, the activity was in fullscreen.
I'm trying to animate an image view that I'm using as a background in my activity but the app crashes when loading the activity. All the images and the .xml file are in the drawable-hdpi folder so I'm not sure why it's not finding it. Please let me know if there is a better way to set an animation as an activity background.
Heres my .xml file for the animation:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/selected" android:oneshot="false">
<item android:drawable="#drawable/bow1" android:duration="60" />
<item android:drawable="#drawable/bow2" android:duration="60" />
<item android:drawable="#drawable/bow3" android:duration="60" />
<item android:drawable="#drawable/bow4" android:duration="60" />
<item android:drawable="#drawable/bow5" android:duration="60" />
<item android:drawable="#drawable/bow6" android:duration="60" />
<item android:drawable="#drawable/bow7" android:duration="60" />
<item android:drawable="#drawable/bow8" android:duration="60" />
<item android:drawable="#drawable/bow9" android:duration="60" />
</animation-list>
Heres the code I'm using to try run it:
public class MainActivity extends Activity {
ImageView bground;
AnimationDrawable bganim;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.activity_main);
bground = (ImageView)findViewById(R.id.background);
bground.setBackgroundResource(R.drawable.bowanimbg);
bganim = (AnimationDrawable) bground.getBackground();
bganim.start();
}
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lucidity/com.example.lucidity.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable-xxhdpi/bowanimbg.xml from drawable resource ID #0x7f02000b
I would put this in a comment, but unfortunately I don't have a high enough rep. So I'll do my best to solve the problem.
You mentioned that all of the images were present in the drawable-hdpi folder. But if you notice the error, it looks like it is searching for the file in the res/drawable-xxhdpi folder. What I would suggest is copying the .xml files from the -hdpi folder into the -xxhdpi folder and seeing if it works!
Fixed it!! Since it wasn't loading the animation at all I decided to make an onWindowFocusedChanged method so that it would load the animation once the activity had loaded. I also set the background of the imageview to my bowanimbg.xml file in the .xml which I initially thought wouldn't be necessary.
public void onWindowFocusChanged(boolean hasFocus) {
bground = (ImageView)findViewById(R.id.background);
bground.setImageResource(R.drawable.bowanimbg);
bganim = (AnimationDrawable) bground.getBackground();
if (hasFocus) {
bganim.start();
}
else {
bganim.stop();
}