Rol*_*f ツ 9 android android-appcompat android-fragments material-design
当使用AppCompat 22.1.0使用基于xml的布局时,并非所有支持的小部件都使用Android 4.4为我的片段着色或材料为主题.
我看到以下小部件的这种行为(其他未经测试):
它曾经在AppCompat v22.0.0中工作.
截图(左4.4,右5.0):

MainActivity.java:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
Run Code Online (Sandbox Code Playgroud)
fragment_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="RadioButton test"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="CheckBox test"/>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/someStrings"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
的themes.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"></style>
</resources>
Run Code Online (Sandbox Code Playgroud)
Rol*_*f ツ 11
目前报告为错误:https://code.google.com/p/android/issues/detail?id = 169760
临时解决方法是使用Fragment父Activity LayoutInflater:getActivity().getLayoutInflater()而不是onCreateView方法中提供的LayoutInflater.
例:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = getActivity().getLayoutInflater().inflate(R.layout.fragment_main, container, false);
return rootView;
}
Run Code Online (Sandbox Code Playgroud)
注意:另一种解决方案是在xml布局中使用特殊的AppCompat小部件:
但这基本上意味着您需要用AppCompat替换每个小部件.
| 归档时间: |
|
| 查看次数: |
3367 次 |
| 最近记录: |