Cannot find R.layout.activity_main

I had the same problem, fixed by replacing R with com.example.appname.R obviously put your package reference in there instead. Or just add this line to your file: import com.your.package.R Or even better, try removing this line from your code if exists: import android.support.compat.R

Layout problem with button margin

Remember, android:layout_* attributes are LayoutParams. They are arguments to the parent and affect how the parent will perform layout on that view. You’re specifying layout_margin attributes on your buttons, but they’re getting ignored. Here’s why: Since LayoutParams are specific to the parent view type, you need to supply an instance of the correct parent type … Read more

Android – use external profile image in notification bar like Facebook

This statement will use a method to convert a URL (naturally, one that points to an image) into a Bitmap. Bitmap bitmap = getBitmapFromURL(“https://graph.facebook.com/YOUR_USER_ID/picture?type=large”); Note: Since you mention a Facebook profile, I have included an URL that gets your the large size profile picture of a Facebook User. You can however, change this to any … Read more

Stop fragment refresh in bottom nav using navhost

Try this: public class MainActivity extends AppCompatActivity { final Fragment fragment1 = new HomeFragment(); final Fragment fragment2 = new DashboardFragment(); final Fragment fragment3 = new NotificationsFragment(); final FragmentManager fm = getSupportFragmentManager(); Fragment active = fragment1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); … Read more

Newer versions of Android Studio add only two drawable directories – drawable and drawable-v21

Thank you to everyone who tried to help. You helped me reach the final answer, but no one solution was quite right. @user3137702 was probably the closest, as it IS related to the whole move to vectors/SVGs. I couldn’t find a definitive answer, like something directly from Google (although I imagine it is out there), … Read more

Android SlidingTabLayout with icons

Just want to give example for the Correct and accepted answer. 🙂 Firstly, add the tabs and set their custom view when you are adding the adapter to your viewpager. For example see following lines: mViewpager = (ViewPager) view.findViewById(R.id.pager); //Do something with your view before setting up adapter ViewPager.setAdapter(mSectionsPagerAdapter); mSlidingTabLayout = (SlidingTabLayout) View().findViewById(R.id.sliding_tabs); mSlidingTabLayout.setCustomTabView(R.layout.custom_tab_title, R.id.tabtext); … Read more