我想将自定义字体应用于我的应用程序的标题,该标题显示在ActionBar上.以前我没有使用任何支持库和这个解决方案:
int titleId = getResources().getIdentifier("action_bar_title", "id",
"android");
TextView yourTextView = (TextView) findViewById(titleId);
yourTextView.setTypeface(face);
Run Code Online (Sandbox Code Playgroud)
对我来说很好.但是现在我使用材质设计SupportActionBar,这会抛出NullPointerException.那么如何在使用AppCompat时更改ActionBar字体?
android android-layout android-fonts android-actionbar android-actionbar-compat
我试图测试当我执行HomePresenter类的方法"onCreate(IHomeView iHomeView)"时调用"setTabs()"."SetTabs()"是IHomeView中的接口方法.为了测试它,我使用mockito,但是当我调用homeView.setTabs()时,我得到一个illegalArgumentException
我把我的代码放在这里,很简单:
我的简单测试:
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.robolectric.util.FragmentTestUtil.startFragment;
@RunWith(RobolectricTestRunner.class)
public class HomeFragmentTest {
@Test
public void testOnCreateHomePresenter() {
IHomeView homeViewMock = mock(IHomeView.class);
HomePresenter homePresenter = new HomePresenter();
homePresenter.onCreate(homeViewMock);
verify(homeViewMock, times(1)).setTabs();
}
}
Run Code Online (Sandbox Code Playgroud)
IHomeView.class
public interface IHomeView {
public void setTabs();
}
Run Code Online (Sandbox Code Playgroud)
HomePresenter.java
public class HomePresenter implements IHomePresenter {
private IHomeView mHomeView;
public void onCreate(IHomeView homeView) {
mHomeView …Run Code Online (Sandbox Code Playgroud)