如何设置ImageButton属性
app:srcCompat="@drawable/pic"
Run Code Online (Sandbox Code Playgroud)
编程?
像是myImageButton.setBackgroundResource(R.drawable.eng2);属性的东西app:srcCompat.
使用support-v4库22.1.0 android支持嵌套滚动(pre android 5.0).不幸的是,这个功能并没有真正记录.有两个接口(NestedScrollingParent和NestedScrollingChild)以及两个辅助委托类(NestedScrollingChildHelper和 NestedScrollingParentHelper).
有没有人在Android上使用NestedScrolling?
我尝试设置一个小例子,我使用NestedScrollView实现两者NestedScrollingParent和NestedScrollingChild.
我的布局看起来像这样:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:id="@+id/header"
android:layout_width="match_parent" android:layout_height="100dp"
android:background="#AF1233"/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/child"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#12AF33"
android:text="@string/long_text"/>
</FrameLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
我想在(id = parent)中显示a header view和另一个NestedScrollView(id = child NestedScrollView).
我们的想法是,在运行时使用以下方法调整子滚动视图的高度OnPredrawListener:
public class MainActivity extends Activity {
@Override protected void onCreate(Bundle …Run Code Online (Sandbox Code Playgroud) 我有一个Activity继承自AppCompactActivity.在活动集主题的清单中:
<style name="Theme.custom" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="colorButtonNormal">@color/accent</item>
<item name="android:buttonStyle">@style/ButtonStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
当我运行活动时,它显示为对话框,但显示标题!我尝试supportRequestWindowFeature(Window.FEATURE_NO_TITLE), RequestWindowFeature(Window.FEATURE_NO_TITLE)但标题仍然显示.请让我知道,有什么问题?
编辑
我解决了,只android:windowNoTitle改为 windowNoTitle!因为我使用的是AppCompactActvity!
标题很自我解释.
以下代码不会在浮动操作按钮下方渲染阴影.渲染阴影可以做些什么?即使在API 21+上也不支持此功能吗?
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/ic_add"
android:clickable="true" />
Run Code Online (Sandbox Code Playgroud)
注意:添加android:elevation不会在API 21上添加阴影.

屏幕截图取自dandar3:https: //github.com/dandar3/android-support-design
android android-appcompat floating-action-button android-design-library
好的,所以我是android开发的初学者,我刚创建了hello world app.但是它给了我库中styles_base.xml文件的错误appcompat_v7.
错误:检索项目的父项时出错:找不到与给定名称"android:Widget.Material.ActionButton"匹配的资源.styles_base.xml/appcompat_v7/res/values-v21
AAPT问题
我该如何处理这个错误?另外,为什么我不想要appcompat_v7库?我的意思是如何在不使用appcompat_v7库的情况下创建hello world应用程序?
这是styles_base.xml给出上述错误的文件.
<resources>
<!-- Like in themes_base.xml, the namespace "*.AppCompat.Base" is used to
define base styles for the platform version. The "*.AppCompat"
variants are for direct use or use as parent styles by the app. -->
<eat-comment/>
<style name="Base.Widget.AppCompat.ActionBar.TabView"
parent="android:Widget.Material.ActionBar.TabView">
</style>
<style name="Base.Widget.AppCompat.Light.ActionBar.TabView"
parent="android:Widget.Material.Light.ActionBar.TabView">
</style>
<style name="Base.Widget.AppCompat.ActionBar.TabText"
parent="android:Widget.Material.ActionBar.TabText">
</style>
<style name="Base.Widget.AppCompat.Light.ActionBar.TabText"
parent="android:Widget.Material.Light.ActionBar.TabText">
</style>
<style name="Base.Widget.AppCompat.Light.ActionBar.TabText.Inverse"
parent="android:Widget.Material.Light.ActionBar.TabText">
</style>
<style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Menu"
parent="android:TextAppearance.Material.Widget.ActionBar.Menu">
</style>
<style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Title"
parent="android:TextAppearance.Material.Widget.ActionBar.Title">
</style>
<style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
parent="android:TextAppearance.Material.Widget.ActionBar.Subtitle"> …Run Code Online (Sandbox Code Playgroud) 我使用ActionBarActivity从Android 5 SDK,这里是我的theme.xml为V21
<style name="AppTheme_Light" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:colorPrimary">@color/abc1</item>
<item name="android:colorPrimaryDark">@color/abc2</item>
<item name="android:colorAccent">@color/abc3</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但颜色被忽略,并被默认的蓝绿色替换,所有对话框都显示没有填充.
问题http://i62.tinypic.com/21cebcz.png
此外,填充在其他地方也被忽略,如自定义吐司,问题只发生在棒棒糖设备中.
编辑:
填充问题是由于fitsSystemWindow我解决了
这个问题..
但是重音颜色问题仍然存在,它不仅影响对话框而且影响整个应用程序.
android android-appcompat android-support-library material-design android-5.0-lollipop
我尝试在我的应用程序中使用CardView,它在我的xml布局中工作得很好.由于我想在我的代码中生成它们而不是通过xml,我尝试使用CardView.setRadius()设置半径 - Android开发人员建议的方法(https://developer.android.com/preview/material/ui-widgets .html #cardview).
这根本不起作用!我希望有人可以帮助我解决我的问题,或者通过xml布局得到一个很好的解决方法.
这是我的代码:
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
float radius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
for (String color : colors) {
CardView card = new CardView(getActivity());
TextView text = new TextView(getActivity());
card.setBackgroundColor(Color.parseColor("#"+color));
card.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, height));
card.setRadius(radius); //Error!!
text.setText(args.get(colors.indexOf(color)) + " - #" + color);
card.addView(text);
group.addView(card);
}
Run Code Online (Sandbox Code Playgroud)
这是我的日志:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brobox.materialcolorpalette/com.brobox.materialcolorpalette.MainActivity}: java.lang.ClassCastException: android.graphics.drawable.ColorDrawable cannot be cast to android.support.v7.widget.RoundRectDrawableWithShadow
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2212)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102) …Run Code Online (Sandbox Code Playgroud) 我正在使用Appcompat V7库中的新工具栏,我正在使用导航抽屉和片段制作应用程序.
在一些片段中,我不想显示汉堡包图标而是显示箭头......我很好,我这样做:
mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
Run Code Online (Sandbox Code Playgroud)
我的问题是:我需要如何或在哪里设置主页按钮lisener或我需要听"后退"按钮?我想调用主要的反向方法并使用汉堡包图标设置导航抽屉图标.
我目前正忙着使用新的AppCompat库,为旧设备带来材料设计.
将工具栏设置为操作栏对我来说很好,但工具栏似乎在调用时没有做任何事情inflateMenu(int resId).从文档中,我认为这是替换getMenuInflater().inflate(int resId)来自onCreateOptionsMenu的调用.如果我做后者,菜单项正确膨胀并添加到工具栏,但inflateMenu似乎没有.
我错过了什么?
活动代码:
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.main); // this does nothing at all
setSupportActionBar(toolbar);
}
// this works
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我正在尝试将我的应用程序转换为使用v21 AppCompat库,因此我开始使用工具栏而不是ActionBar.在我的所有常规活动(扩展ActionBarActivity)中,一切都很好.但在我的SettingsActivity中扩展了PreferenceActivity,因此我无法使用setSupportActionBar(actionbar)调用,我需要使用"独立"工具栏.工具栏显示,但我无法弄清楚如何将"home/up"按钮添加到工具栏.
SettingsActivity.java:
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Toolbar actionbar = (Toolbar) findViewById(R.id.actionbar);
if (null != actionbar) {
// In every other activity that extends ActionBarActivity I simply use:
// setSupportActionBar(actionbar);
// final ActionBar supportActionBar = getSupportActionBar();
// supportActionBar.setDisplayHomeAsUpEnabled(true);
// but in PreferenceActivity you need to add a standalone toolbar:
actionbar.setTitle(R.string.title_activity_settings);
actionbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SettingsActivity.this.finish();
}
});
// Inflate a menu to be displayed in …Run Code Online (Sandbox Code Playgroud) android android-appcompat android-actionbar-compat android-toolbar