在我的NavigationView中,我有一个标题布局,其id为'viewId',带有活动按钮.要设置这些按钮,我在活动中执行以下操作onPostCreate:
final View panel = findViewById(R.id.viewId);
panel.setOnClickListener(new View.OnClickListener() {
... setup goes here ...
});
Run Code Online (Sandbox Code Playgroud)
使用新版本的android支持库(23.1.0),无法找到视图,它返回null.以前的版本运行良好.这是一个错误还是我使用此功能错了?如果是这样,如何访问标题布局并向其添加行为?
android android-support-library android-design-library navigationview
我已将appCompat材质设计添加到我的应用程序中,似乎警报对话框未使用我的primary,primaryDark或强调颜色.
这是我的基本风格:
<style name="MaterialNavyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/apptheme_color</item>
<item name="colorPrimaryDark">@color/apptheme_color_dark</item>
<item name="colorAccent">@color/apptheme_color</item>
<item name="android:textColorPrimary">@color/action_bar_gray</item>
</style>
Run Code Online (Sandbox Code Playgroud)
根据我的理解,对话框按钮文本也应该使用这些颜色.我的理解是错的还是我还需要做些什么?
解:
明确的答案让我走上正轨.
<style name="MaterialNavyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/apptheme_color</item>
<item name="colorPrimaryDark">@color/apptheme_color_dark</item>
<item name="colorAccent">@color/apptheme_color</item>
<item name="android:actionModeBackground">@color/apptheme_color_dark</item>
<item name="android:textColorPrimary">@color/action_bar_gray</item>
<item name="sdlDialogStyle">@style/DialogStyleLight</item>
<item name="android:seekBarStyle">@style/SeekBarNavyTheme</item>
</style>
<style name="StyledDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">@color/apptheme_color</item>
<item name="colorPrimaryDark">@color/apptheme_color_dark</item>
<item name="colorAccent">@color/apptheme_color</item>
</style>
Run Code Online (Sandbox Code Playgroud) android android-appcompat android-support-library material-design material-components-android
我正在尝试从默认的android迁移AlertDialog到appCompat-22.1中包含的新的android 到目前为止我了解你只需导入android.support.v7.app.AlertDialog包以便使用它.
但我怎么样呢呢?例如,更改正/负按钮颜色,标题颜色,消息颜色和背景颜色?
android android-appcompat android-alertdialog android-support-library
Google NavigationView在设计支持库版本22.2.0中引入了该版本,您可以使用菜单资源轻松创建抽屉.
如何在两个项目之间创建简单的分隔线?对项目进行分组不起作用.创建子项目部分会创建一个分隔线,但它需要一个我不想要的标题.
任何帮助,将不胜感激.
android android-support-library navigation-drawer android-design-library navigationview
我想知道android-support-v4.jar 和android-support-v7-appcompat.jar之间的区别.如果我想在我的应用程序中添加appcompat Action Bar,我需要添加android-support-v7-appcompat.jar和android-support-v4.jar,或者只添加android-support-v7-appcompat.jar.
另外,android-support-v13.jar有appcompat吗?
android android-compatibility android-4.0-ice-cream-sandwich android-support-library android-actionbar-compat
我有一个FragmentActivity,我想在其中使用一个地图片段.我在获取支持片段管理器访问它时遇到问题.
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map1)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title("Hello Maps ");
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(latitude, longitude)).zoom(15).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
// adding marker
googleMap.addMarker(marker);
Run Code Online (Sandbox Code Playgroud) android android-fragments android-fragmentactivity android-support-library fragmentmanager
我正在使用TextInputLayout设计库中的新功能.我可以让它显示并更改浮动标签的颜色.不幸的是,实际EditText提示现在总是白色的.
我试过用XML,样式和编程方式更改hintColor,并尝试使用android.support.v7.widget.AppCompatEditText
但EditText提示总是显示白色.
这是我TextInputLayout和我的XMLEditText
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android.support.design:hintTextAppearance="@style/GreenTextInputLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/city"
android:textColorHint="@color/black"
android:hint="@string/city" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的样式TextInputLayout(我尝试将hintTextColor属性设为黑色,但没有为我做任何事情):
<style name="GreenTextInputLayout" parent="@style/TextAppearance.AppCompat">
<item name="android:textColor">@color/homestory_green</item>
</style>
Run Code Online (Sandbox Code Playgroud) android android-edittext android-textattributes android-support-library android-design-library
我正在尝试在我的导航抽屉菜单中的项目旁边显示一个图标,但由于某种原因,图标始终显示为灰色而不是原始颜色(棕色).有没有办法防止这种情况发生,以显示图标的原始颜色?
MainActivity.java
public class MainActivity extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
if (navigationView != null) {
setupDrawerContent(navigationView);
}
}
private void setupDrawerContent(NavigationView navigationView) {
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
mDrawerLayout.closeDrawers();
return true;
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
drawer_view.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Section">
<menu>
<item
android:id="@+id/navigation_item_1"
android:icon="@drawable/ic_browncircle"
android:title="Sub item 1" />
</menu>
</item>
</menu>
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种方法,使用Android支持库的FileProvider正确地与外部应用程序共享(而不是OPEN)内部文件.
按照文档上的示例,
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.android.supportv4.my_files"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/my_paths" />
</provider>
Run Code Online (Sandbox Code Playgroud)
并使用ShareCompat将文件共享给其他应用程序,如下所示:
ShareCompat.IntentBuilder.from(activity)
.setStream(uri) // uri from FileProvider
.setType("text/html")
.getIntent()
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
Run Code Online (Sandbox Code Playgroud)
不起作用,因为FLAG_GRANT_READ_URI_PERMISSION仅授予data对intent 指定的Uri的权限,而不授予EXTRA_STREAMextra 的值(由set设置setStream).
我试图通过设置成安全android:exported到true的供应商,但FileProvider在内部检查,如果本身是出口,所以时,它抛出一个异常.
android android-contentprovider android-support-library android-fileprovider
操作栏兼容性已添加到支持库,修订版18中.它现在具有ActionBarActivity用于在旧版Android上使用操作栏创建活动的类.
有没有办法从支持库添加Action Bar PreferenceActivity?
以前我用ActionBarSherlock,它有SherlockPreferenceActivity.
android preferenceactivity android-actionbar android-support-library