1. 程式人生 > >ActionBarCompat (Part 3): Migrating from ActionBarSherlock

ActionBarCompat (Part 3): Migrating from ActionBarSherlock

After learning some basic rules to work with ActionBarCompat, you will probably need to migrate some apps from ActionBarSherlock to ActionBarCompat, because it provides better integration with some other functionalities such as Navigation Drawer, and there are some issues that you must know to make it easy. I’ll be replacing

Bandhook Action Bar while writing this post, so there may be some points I won’t cover if I’m not using them. Please feel free to explain in comments section and I will add it.

Import AppCompat project

As I explained on a previous post, an apklib project is required to use ActionBarCompat. Gradle allows some easier integrations in Android Studio, but I can imagine most of us still use Eclipse or IntelliJ, so the easiest way will be to import as a project or module. Remember you can find it at sdk\extras\android\support\v7\appcompat

. Adding both jars under libs into the main project may also be necessary.

Replace SherlockFragmentActivity with ActionBarActivity

ActionBarActivity is the new activity to be used with ActionBarCompat, and it allows the use of fragments. If you have any other kind of Sherlock Activities, replace them too. There shouldn’t be any problems even if you are not using fragments.

Replace SherlockFragment with Fragment

Use support-v4 fragments instead of the ones in ActionBarSherlock.

Change Menu, MenuItem and getSupportMenuInflater() references

AppCompat will use native ones instead. ActionBar package reference must also be modified. Modify menu xml resources as explained in previous post.

Modify the way you get Action Views

If you read part 2 of this series, I explained there’s a compatibility class to do this task. It won’t fail on new versions if you don’t change it, but old versions will crash.

mSearchView = (SearchView)MenuItemCompat.getActionView(mSearchItem)

Modify your Themes and Styles

Make your theme extend some of the AppCompat ones. For instance, you can use: Theme.AppCompat.Light.DarkActionBar. Replace every Sherlock appearance in styles with AppCompat. Alternatively you can use Action Bar Style Generator, which is already optimized to work with AppCompat.

Want to learn Kotlin?

Check my free guide to create your first project in 15 minutes!

And that’s all! I got ActionBarCompat working on Bandhook easier than I expected. Jake Wharton did a great job, as he explained in its own blog, when creating its library to be easily replaced.

ActionBarCompat from ActionBarSherlock

I’m in love with Kotlin. I’ve been learning about it for a couple of years, applying it to Android and digesting all this knowledge so that you can learn it with no effort.

Shares

Like this:

Like Loading...

相關推薦

ActionBarCompat (Part 3): Migrating from ActionBarSherlock

After learning some basic rules to work with ActionBarCompat, you will probably need to migrate some apps from ActionBarSherlock to ActionBarCompat,

Migrating from ActionBarSherlock to ActionBarCompat

In July 2013 Google announced ActionBarCompat as part of its support library package. This library makes it easy to u

Migrating from Spring 3 to Spring 4 - org.springframework.scheduling.quartz.CronTriggerBean

can EDA utils jobdetail data- found ble ever OS I‘m trying to migrate from spring 3.0.5 to spring 4.1.X . Spring 3 has Class named as "or

Lesson 2 Building your first web page: Part 3

create should bsp str process .html anything step rule Time to build your first HTML page by hand I could go on with more theory and sen

多線程編程-- part 3 多線程同步->synchronized關鍵字

靜態方法 mage rri pri alt image col ring 釋放 多線程同時訪問一個資源,可以會產生不可預料的結果,所以為這個資源加鎖,訪問資源的第一個線程為其加鎖後,其他線程便不能在使用那個資源,直到鎖被解除。 舉個例子: 存款1000元

Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070058 android-studio 3.0 from canary 5 to canary 6

time cat -1 int pre lac patch check caused 我升級android-studio到了3.0 canary 6打包編譯安裝出現如下錯誤: 07-11 13:00:39.523 8913-8913/dcpl.com.myapplic

JSP復習(part 3

響應頭 utf 瀏覽器 聲明 數據 thead code 直接 web服務器 3.4.4 request對象提供了一些用來獲取客戶信息的方法,利用這些方法,可以獲取客戶端的IP地址 協議等有關信息 3.5 request對象和response對象相對應,用於

深度學習系列 Part(3)

舉例 call 連接 update 裏的 就會 1.5 upd layers 這是《GPU學習深度學習》系列文章的第三篇,主要是接著上一講提到的如何自己構建深度神經網絡框架中的功能模塊,進一步詳細介紹 Tensorflow 中 Keras 工具包提供的幾種深度神經網絡模塊。

深度剖析Kubernetes API Server三部曲 - part 3

回收 上下文 1.7 cal second 時間 如果 watch date 在本系列的前兩部分中我們介紹了API Server的總體流程,以及API對象如何存儲到etcd中。在本文中我們將探討如何擴展API資源。在一開始的時候,擴展API資源的唯一方法是擴展相關API源代

Python Chapter 9: 使用Tkinter進行GUI程序設計 Part 3

comm idt com title ear and elf 設計 port 9. 菜單 使用Menu類創建菜單欄和菜單,再使用add_command方法給菜單增加條目。 1 # Program 9.13 2 from tkinter import * 3 4

Brian2學習教程——Intro to Brian part 3: Simulations

英文原文:brian2官方tutorials 中文翻譯:【Brian2學習教程之三】Introduction to Brian part 3: Simulations 本文首先對模擬中涉及到的神經元模型進行介紹,並對最後一個例程的實現機制進行分析。 目錄 脈衝神經元模型 Hodg

STARKs,Part-3:攻堅(下)

感謝上帝,今天是 FRI 日(即“快速裡德-所羅門碼接近性互動預言證明(Fast Reed-Solomon Interactive Oracle Proofs of Proximity)”) 提醒:現在可能是審閱和重讀本系列第 2 部分的好時機。 現在,我們來探討建立低次證明的程式碼

STARKs,Part-3:攻堅(上)

特別感謝 Eli ben Sasson 一如既往地提供幫助;也特別感謝 Chih-Cheng Liang和Justin Drake 的審閱。 為本系列的第 1 部分和第 2 部分的後續內容,本文將介紹在實際中實現 STARK 的途徑與效果,並使用 python 語言進行實現。STARKs

Object Detection In Tensorflow - Part 3

Object Detection in Tensorflow in Real-Time Detection Github So in this blog post, I won’t not show a effect picture or video, because it’s

[Testing] Config jest to test Javascript Application -- Part 3

Run Jest Watch Mode by default locally with is-ci-cli In CI, we don’t want to start the tests in watch mode, but locally we normally want to run the tests

2018/深入淺出Rust-Future-Part-3

譯自Rust futures: an uneducated, short and hopefully not boring tutorial - Part 3 - The reactor 本文時間:2018-12-03,譯者: motecshine, 簡介:motecshine 歡迎向Rust中文社群投稿

深入淺出經典面試題:從瀏覽器中輸入URL到頁面載入發生了什麼 - Part 3

深入淺出經典面試題:從瀏覽器中輸入URL到頁面載入發生了什麼 - Part 3 備註: 因為文章太長,所以將它分為三部分,本文是第三部分。 第一部分:深入淺出經典面試題:從瀏覽器中輸入URL到頁面載入發生了什麼 - Part 1 第二部分:深入淺出經典面試題:從瀏覽器中輸入URL到頁

Understanding Feature Engineering (Part 3) — Traditional Methods for Text Data

Introduction We have covered various feature engineering strategies for dealing with structured data in the first two parts of this series. Che

計算機系統結構--複習(Part 3

陸續補充ing 往期回顧: Part 1(chapter 1 - chapter 5):https://blog.csdn.net/zongza/article/details/83780572 Part 2(chapter 5 - chapter 10):https:/

# [cs231n (七)神經網路 part 3 : 學習和評估 ][1]

標籤(空格分隔): 神經網路 0.回顧 cs231n (一)影象分類識別講了KNN cs231n (二)講了線性分類器:SVM和SoftMax cs231n (三)優化問題及方法 cs231n (四)反向傳播 cs231n (五)神經網路 part 1: