-1

I want to add my ActionBar in all of my activities and then the FloatingActionButton as well. How can I do that?

Here is my main activity

SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)getView().findViewById(R.id.imageView);
Hannah
  • 11
  • 7

3 Answers3

1

you can create one base activity :-

 public abstract class BaseActivity extends AppCompatActivity {

  Toolbar toolbar;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutResource());
    configureToolbar();
  }

  protected abstract int getLayoutResource();

  private void configureToolbar() {
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
      setSupportActionBar(toolbar);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
  }
}

and you can extend this base activity :-

public class MainActivity extends BaseActivity {


     @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      }

      @Override
      public int getLayoutResource() {
        return R.layout.activity_main;
      }
    }
santosh kumar
  • 2,952
  • 1
  • 15
  • 27
0

Write these lines in your Second activity in OnCreate Method:

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    getSupportActionBar().setTitle("Your Title");
Ravish Sharma
  • 207
  • 2
  • 14
  • In my second activity it have "extends TileViewActivity" the codes is not AppCompatActivity cause im using tileview library. the codes you provide is not working. – Hannah Jan 06 '17 at 11:55
0
<activity
        android:name="com.example.Activity"
        android:label="Main"
        android:theme="@style/MyTheme" >

And in style.xml

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">#ffffff</item>
    <item name="android:backgroundSplit">#000000</item>
</style>
Sunil Chaudhary
  • 1,221
  • 12
  • 25