0

I am creating an app which can work with Japanese locale When I run the application in English i.e default locale it works fine without any exeception but when I change the locale and run the same the application crashes at the point of getSupportActionBar()

I have not used any theme and the default theme is as follows

<style name="AppBaseTheme" parent="android:Theme.Light">

My code is as follows MainActivity.java

public class MainActivity extends SherlockFragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ActionBar actionbar = getSupportActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionbar.setTitle("PROFILE");
Tab frag1tab = actionbar.newTab().setText("LOGIN");
Tab frag2tab = actionbar.newTab().setText("REGISTER");

Fragment fragment1 = new LoginFragment();
Fragment fragment2 = new RegistrationFragment();

frag1tab.setTabListener(new MyTabListener(fragment1));
frag2tab.setTabListener(new MyTabListener(fragment2));

actionbar.addTab(frag1tab);
actionbar.addTab(frag2tab);

}

class MyTabListener implements TabListener {
public Fragment fragment;

public MyTabListener(Fragment fragment) {
    this.fragment = fragment;

}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub

}

@Override
public void onTabSelected(Tab arg0, FragmentTransaction ft) {
    // TODO Auto-generated method stub
    ft.replace(R.id.fragment_container, fragment);

}

@Override
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
    // TODO Auto-generated method stub

}

}

}

LoginFragment Code

   public class LoginFragment extends SherlockFragment implements OnClickListener{
URLConnection url;
JSONObject j1;
View v;
EditText UserName;
EditText Password;
int result;
Button btn1;
StringBuffer br;
Handler h;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
     v=inflater.inflate(R.layout.login_fragment, container,false);
    Log.d("Fragment_1", "MIKEL - onCreateView");
    h=new Handler();

    UserName=(EditText) v.findViewById(R.id.username);
     Password=(EditText) v.findViewById(R.id.password);


    btn1=(Button) v.findViewById(R.id.loginButton);


     btn1.setOnClickListener(this);


     // currentContext.startActivity(activityChangeIntent);


     return v;

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    }
  }

And similar code for other fragment

My Strings.xml in values folder is as follows.

<resources>
<string name="app_name">Internationalization and Localization</string>
<string name="hello">Hello World.</string>

<string name="byebye">Bye bye World</string>
<string name="button">Change Text</string>
</resources>

My Strings.xml in values-ja folder is as follows.

 <?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">国際化と現地化&lt;/string>
<string name="hello">こんにちは、みなさん </string>
 <string name="byebye">さようなら、みなさん&lt;/string>
<string name="button">テキストを変える</string> 
</resources>
4

2 回答 2

1

您必须更改主题。检查这个里面的清单

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Sherlock" >
于 2013-10-25T13:48:36.403 回答
0

我设置 ActionBarSherlock 的方式是:

private void initActionBar() {
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    getSupportActionBar().setCustomView(R.layout.actionbar_main);
}

我在您的活动布局上方膨胀新布局。我在 super.onCreate(savedInstanceState); 之前调用 initActionBar() 方法

布局可能看起来像这样(例如):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/bg_actionbar">

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/img_actionbar_logo"
        android:layout_centerVertical="true" />
 OR ANYTHING ELSE YOU WANT HERE/BUTTONS/TEXTVIEWS/etc.

</RelativeLayout>

您需要调用清单的应用程序 android:theme="@style/Theme.Sherlock">。如果您不想在活动中使用 actionBarSherlock,则必须手动设置它,例如:

<activity

            android:name="pl.toptof.android.ui.activity.SplashActivity"
            android:theme="@style/Theme.Styled.NoActionBar"   
</activity>

您必须记住的另一件事是您不再使用“Activity”和“Fragment”类,而是使用 SherlockActivity 和 SherlockFragment 或 SherlockFragmentActivity。

于 2013-10-25T14:02:26.983 回答