【问题标题】:FloatingActionButton! Why it does not work?浮动动作按钮!为什么它不起作用?
【发布时间】:2015-07-15 20:43:00
【问题描述】:
  public class Advertisment extends Fragment  {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View v = inflater.inflate(R.layout.fragment_advertisment, container, false);

        if(Build.VERSION.SDK_INT< Build.VERSION_CODES.LOLLIPOP){
            FloatingActionButton fab=(FloatingActionButton)v.findViewById(R.id.fab);
            fab.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View arg){
                    Intent myIntent = new Intent(getActivity(), WriteAdvert.class);
                    startActivity(myIntent);
                }
            });
        }

}

我使用库https://github.com/shell-software/fab

这个按钮应该转到另一个活动,但它没有。 我是初学者!

【问题讨论】:

    标签: android button android-fragments fragment floating-action-button


    【解决方案1】:

    您是否在 Android manifest.xml 文件中添加了目标活动?

    <application>
      <activity
            android:name="com.mycompany.myfirstapp.DisplayMessageActivity"
            android:label="@string/title_activity_display_message"
            android:parentActivityName="com.mycompany.myfirstapp.MyActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.mycompany.myfirstapp.MyActivity" />
        </activity>
    </application>
    

    【讨论】:

    • prntscr.com/728q5u 您的按钮属于 ActionButton 类型,而不是 FloatingActionButton(参见链接)。仔细查看 github 自述文件,了解如何调用按钮
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-03
    • 2019-09-04
    相关资源
    最近更新 更多