I am trying to use toolbar in my app, for this purpose i have create a xml file name my_action_bar
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/my_action_bar_toolbar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/orange"
android:minHeight="200dp"
>
<ImageView
android:id="@+id/imgageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dog"/>
</android.support.v7.widget.Toolbar>
</LinearLayout>
This is my MainActivity code
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//action bar toolbar
Toolbar actionBarToolbar = (Toolbar) findViewById(R.id.my_action_bar_toolbar);
//important that is set first
setSupportActionBar(actionBarToolbar);
but it shows an error line on set support action bar set support action bar cannot be applied
How to resolve this error I am using Min API is 11 Any suggestion will be appreciated, Thanks in advance
You need to change your import from,
import android.widget.Toolbar;
to
import android.support.v7.widget.Toolbar;
or
In Androidx
you can use
import androidx.appcompat.widget.Toolbar;
This will surely solve the problem.
Change your import to
import android.support.v7.widget.Toolbar;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With