Reputation: 768
I am Using the ToolBar in my app . When i am trying to use tool bar app is crashing.
"java.lang.NoSuchFieldError: android.support.v7.appcompat.R$styleable.ActionBarWindow ".
I went through stackoverflow answers but none of them solves my problem.
Here is my Code :
app_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green_background_color">
</android.support.v7.widget.Toolbar>
Theme for Activity :
<style name="NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
</style>
Manifest Declaration:
<activity
android:name="in.chabu.activities.SignUpActivity"
android:label="@string/title_activity_sign_up"
android:theme="@style/NoActionBar">
</activity>
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.chabu.activities.SignUpActivity" >
<include
android:id="@+id/tool_bar"
layout="@layout/app_bar" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tool_bar"
android:text="@string/hello_world" />
</RelativeLayout>
Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
}
I am using Eclipse IDE
.
Upvotes: 1
Views: 4485
Reputation: 418
MainActivity
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
style
<style name="DevenTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/my_primary_color</item>
<item name="colorPrimaryDark">@color/my_primary_dark_color</item>
<item name="colorAccent">@color/my_accent_color</item>
<item name="colorControlNormal">@color/my_control_normal_color</item>
<item name="colorControlActivated">@color/my_control_activated_color</item>
<item name="colorControlHighlight">@color/my_control_highlight_color</item>
</style>
manifest
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/DevenTheme" >
xml
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"/>
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_height="100dp"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:paddingTop="40dp"
android:elevation="5dp" />
In style you can skip all the colors, since those for material design looks.
Upvotes: 0
Reputation: 9009
Strange, but building appCompact-v7-lib
and My project
solved the problem.
Upvotes: 0
Reputation: 8058
Modify your style as below:
<style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>
Upvotes: 1
Reputation: 8337
Try This.....
toolbar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar" <!-- ID of toolbar -->
android:minHeight="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/toolbar_main" />
</LinearLayout>
MainActivity.java
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
}
and you can do it without using any style with NOACTIONBAR.
Upvotes: 0